Skip to content

Commit 5d9d311

Browse files
authored
Merge pull request ceph#64226 from tchaikov/wip-ec-jerasure-fix-leak
erasure-code/jerasure: fix memory leak in Galois field operations Reviewed-by: Ronen Friedman <[email protected]>
2 parents 51679b9 + 08d7363 commit 5d9d311

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/erasure-code/jerasure/jerasure_init.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,23 @@ extern "C" int jerasure_init(int count, int *words)
3535
}
3636
return 0;
3737
}
38+
39+
void jerasure_finish()
40+
{
41+
// jerasure based codings generate matrices using Galois field operations via
42+
// the Jerasure library. The underlying acceleration functions for different
43+
// word sizes are cached in global static variables and initialized lazily.
44+
// These cached functions must be explicitly freed after erasure coding
45+
// operations complete to prevent memory leaks.
46+
// Note:
47+
// - Operations for word sizes > 32 bits are not yet implemented
48+
// - Jerasure only supports word sizes that are power of 2.
49+
static const int words[] = {4, 8, 16, 32};
50+
for (auto w : words) {
51+
gf_t* gf = galois_get_field_ptr(w);
52+
if (gf) {
53+
gf_free(gf, 0);
54+
free(gf);
55+
}
56+
}
57+
}

src/erasure-code/jerasure/jerasure_init.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define CEPH_JERASURE_INIT_H
2020

2121
extern "C" int jerasure_init(int count, int *words);
22+
void jerasure_finish() __attribute__((destructor));
2223

2324
#endif
2425

0 commit comments

Comments
 (0)