Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erasure-code: use new/delete to alloc/free coefficients array #56586

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/erasure-code/isa/ErasureCodeIsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ ErasureCodeIsaDefault::prepare()
dout(10) << "[ cache tables ] creating coeff for k=" <<
k << " m=" << m << dendl;
// build encoding coefficients which need to be computed once for each (k,m)
encode_coeff = (unsigned char*) malloc(k * (m + k));
//
// the coeff array is freed by ErasureCodeIsaTableCache::setEncodingCoefficient
// or ErasureCodeIsaTableCache::~ErasureCodeIsaTableCache()
encode_coeff = new unsigned char[k * (m + k)];

if (matrixtype == kVandermonde)
gf_gen_rs_matrix(encode_coeff, k + m, k);
Expand All @@ -398,7 +401,7 @@ ErasureCodeIsaDefault::prepare()
dout(10) << "[ cache tables ] creating tables for k=" <<
k << " m=" << m << dendl;
// build encoding table which needs to be computed once for each (k,m)
encode_tbls = (unsigned char*) malloc(k * (m + k)*32);
encode_tbls = new unsigned char[k * (m + k)*32];
ec_init_tables(k, m, &encode_coeff[k * k], encode_tbls);

// either our new created table is stored or if it has been
Expand Down
6 changes: 3 additions & 3 deletions src/erasure-code/isa/ErasureCodeIsaTableCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ErasureCodeIsaTableCache::~ErasureCodeIsaTableCache()
for (table_it = tables_it->second.begin(); table_it != tables_it->second.end(); ++table_it) {
if (table_it->second) {
if (*(table_it->second)) {
delete *(table_it->second);
delete[] *(table_it->second);
Svelar marked this conversation as resolved.
Show resolved Hide resolved
}
delete table_it->second;
}
Expand All @@ -75,7 +75,7 @@ ErasureCodeIsaTableCache::~ErasureCodeIsaTableCache()
for (table_it = tables_it->second.begin(); table_it != tables_it->second.end(); ++table_it) {
if (table_it->second) {
if (*(table_it->second)) {
delete *(table_it->second);
delete[] *(table_it->second);
}
delete table_it->second;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ ErasureCodeIsaTableCache::setEncodingCoefficient(int matrix, int k, int m, unsig
if (*ec_out_coeff) {
// somebody might have deposited these coefficients in the meanwhile, so clean
// the input coefficients and return the stored ones
free (ec_in_coeff);
delete[] ec_in_coeff;
return *ec_out_coeff;
} else {
// we store the provided input coefficients and return these
Expand Down