Skip to content

Commit c2fb3ab

Browse files
authored
Merge pull request ceph#56586 from tchaikov/wip-erasure-code-new
erasure-code: use new/delete to alloc/free coefficients array Reviewed-by: Samuel Just <[email protected]>
2 parents d1df8db + 6a88e09 commit c2fb3ab

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/erasure-code/isa/ErasureCodeIsa.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,10 @@ ErasureCodeIsaDefault::prepare()
379379
dout(10) << "[ cache tables ] creating coeff for k=" <<
380380
k << " m=" << m << dendl;
381381
// build encoding coefficients which need to be computed once for each (k,m)
382-
encode_coeff = (unsigned char*) malloc(k * (m + k));
382+
//
383+
// the coeff array is freed by ErasureCodeIsaTableCache::setEncodingCoefficient
384+
// or ErasureCodeIsaTableCache::~ErasureCodeIsaTableCache()
385+
encode_coeff = new unsigned char[k * (m + k)];
383386

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

404407
// either our new created table is stored or if it has been

src/erasure-code/isa/ErasureCodeIsaTableCache.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ErasureCodeIsaTableCache::~ErasureCodeIsaTableCache()
6262
for (table_it = tables_it->second.begin(); table_it != tables_it->second.end(); ++table_it) {
6363
if (table_it->second) {
6464
if (*(table_it->second)) {
65-
delete *(table_it->second);
65+
delete[] *(table_it->second);
6666
}
6767
delete table_it->second;
6868
}
@@ -75,7 +75,7 @@ ErasureCodeIsaTableCache::~ErasureCodeIsaTableCache()
7575
for (table_it = tables_it->second.begin(); table_it != tables_it->second.end(); ++table_it) {
7676
if (table_it->second) {
7777
if (*(table_it->second)) {
78-
delete *(table_it->second);
78+
delete[] *(table_it->second);
7979
}
8080
delete table_it->second;
8181
}
@@ -211,7 +211,7 @@ ErasureCodeIsaTableCache::setEncodingCoefficient(int matrix, int k, int m, unsig
211211
if (*ec_out_coeff) {
212212
// somebody might have deposited these coefficients in the meanwhile, so clean
213213
// the input coefficients and return the stored ones
214-
free (ec_in_coeff);
214+
delete[] ec_in_coeff;
215215
return *ec_out_coeff;
216216
} else {
217217
// we store the provided input coefficients and return these

0 commit comments

Comments
 (0)