diff options
author | Daniel Axtens <dja@axtens.net> | 2017-02-16 17:16:28 +1100 |
---|---|---|
committer | Kota Tsuyuzaki <tsuyuzaki.kota@lab.ntt.co.jp> | 2017-02-21 20:50:03 +0000 |
commit | 4ab1336cabe0c1f5d7fc18c21b78f5d21aca5b60 (patch) | |
tree | f9c3a9074a4a5367a43dd44ac1228af3fff7198f | |
parent | c9136a62b6e7cc8701cd7206ef0367520a20b8b9 (diff) |
jerasure: plug memory leaks
Jerasure inits some global variables on init.
We need to free them, or we'll leak memory.
Partial-Bug: #1666674
Change-Id: Ie7073738428a71910016e910a66dbd92ca98eb92
Signed-off-by: Daniel Axtens <dja@axtens.net>
Notes
Notes (review):
Code-Review+2: Kota Tsuyuzaki <tsuyuzaki.kota@lab.ntt.co.jp>
Workflow+1: Kota Tsuyuzaki <tsuyuzaki.kota@lab.ntt.co.jp>
Verified+2: Jenkins
Submitted-by: Jenkins
Submitted-at: Tue, 21 Feb 2017 21:13:05 +0000
Reviewed-on: https://review.openstack.org/434696
Project: openstack/liberasurecode
Branch: refs/heads/master
-rw-r--r-- | src/backends/jerasure/jerasure_rs_cauchy.c | 21 | ||||
-rw-r--r-- | src/backends/jerasure/jerasure_rs_vand.c | 24 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/backends/jerasure/jerasure_rs_cauchy.c b/src/backends/jerasure/jerasure_rs_cauchy.c index 816b45d..6400ca2 100644 --- a/src/backends/jerasure/jerasure_rs_cauchy.c +++ b/src/backends/jerasure/jerasure_rs_cauchy.c | |||
@@ -63,6 +63,7 @@ typedef int (*jerasure_make_decoding_bitmatrix_func) | |||
63 | (int, int, int, int *, int *, int *, int *); | 63 | (int, int, int, int *, int *, int *, int *); |
64 | typedef void (*jerasure_bitmatrix_dotprod_func) | 64 | typedef void (*jerasure_bitmatrix_dotprod_func) |
65 | (int, int, int *, int *, int,char **, char **, int, int); | 65 | (int, int, int *, int *, int,char **, char **, int, int); |
66 | typedef void (*galois_uninit_field_func)(int); | ||
66 | 67 | ||
67 | /* | 68 | /* |
68 | * ToDo (KMG): Should we make this a parameter, or is that | 69 | * ToDo (KMG): Should we make this a parameter, or is that |
@@ -76,6 +77,9 @@ struct jerasure_rs_cauchy_descriptor { | |||
76 | jerasure_matrix_to_bitmatrix_func jerasure_matrix_to_bitmatrix; | 77 | jerasure_matrix_to_bitmatrix_func jerasure_matrix_to_bitmatrix; |
77 | jerasure_smart_bitmatrix_to_schedule_func jerasure_smart_bitmatrix_to_schedule; | 78 | jerasure_smart_bitmatrix_to_schedule_func jerasure_smart_bitmatrix_to_schedule; |
78 | 79 | ||
80 | /* calls required for free */ | ||
81 | galois_uninit_field_func galois_uninit_field; | ||
82 | |||
79 | /* calls required for encode */ | 83 | /* calls required for encode */ |
80 | jerasure_bitmatrix_encode_func jerasure_bitmatrix_encode; | 84 | jerasure_bitmatrix_encode_func jerasure_bitmatrix_encode; |
81 | 85 | ||
@@ -273,6 +277,7 @@ static void * jerasure_rs_cauchy_init(struct ec_backend_args *args, | |||
273 | cauchy_original_coding_matrix_func initp; | 277 | cauchy_original_coding_matrix_func initp; |
274 | jerasure_matrix_to_bitmatrix_func matrixtobitmatrixp; | 278 | jerasure_matrix_to_bitmatrix_func matrixtobitmatrixp; |
275 | jerasure_smart_bitmatrix_to_schedule_func matrixschedulep; | 279 | jerasure_smart_bitmatrix_to_schedule_func matrixschedulep; |
280 | galois_uninit_field_func uninitp; | ||
276 | jerasure_bitmatrix_encode_func encodep; | 281 | jerasure_bitmatrix_encode_func encodep; |
277 | jerasure_bitmatrix_decode_func decodep; | 282 | jerasure_bitmatrix_decode_func decodep; |
278 | jerasure_erasures_to_erased_func erasedp; | 283 | jerasure_erasures_to_erased_func erasedp; |
@@ -338,6 +343,13 @@ static void * jerasure_rs_cauchy_init(struct ec_backend_args *args, | |||
338 | goto error; | 343 | goto error; |
339 | } | 344 | } |
340 | 345 | ||
346 | func_handle.vptr = NULL; | ||
347 | func_handle.vptr = dlsym(backend_sohandle, "galois_uninit_field"); | ||
348 | desc->galois_uninit_field = func_handle.uninitp; | ||
349 | if (NULL == desc->galois_uninit_field) { | ||
350 | goto error; | ||
351 | } | ||
352 | |||
341 | /* setup the Cauchy matrices and schedules */ | 353 | /* setup the Cauchy matrices and schedules */ |
342 | desc->matrix = desc->cauchy_original_coding_matrix(k, m, w); | 354 | desc->matrix = desc->cauchy_original_coding_matrix(k, m, w); |
343 | if (NULL == desc->matrix) { | 355 | if (NULL == desc->matrix) { |
@@ -385,6 +397,15 @@ static void free_rs_cauchy_desc( | |||
385 | return; | 397 | return; |
386 | } | 398 | } |
387 | 399 | ||
400 | /* | ||
401 | * jerasure allocates some internal data structures for caching | ||
402 | * fields. It will allocate one for w, and if we do anything that | ||
403 | * needs to xor a region >= 16 bytes, it will also allocate one | ||
404 | * for 32. Fortunately we can safely uninit any value; if it | ||
405 | * wasn't inited it will be ignored. | ||
406 | */ | ||
407 | jerasure_desc->galois_uninit_field(jerasure_desc->w); | ||
408 | jerasure_desc->galois_uninit_field(32); | ||
388 | free(jerasure_desc->matrix); | 409 | free(jerasure_desc->matrix); |
389 | free(jerasure_desc->bitmatrix); | 410 | free(jerasure_desc->bitmatrix); |
390 | 411 | ||
diff --git a/src/backends/jerasure/jerasure_rs_vand.c b/src/backends/jerasure/jerasure_rs_vand.c index 0c337a0..b0257a7 100644 --- a/src/backends/jerasure/jerasure_rs_vand.c +++ b/src/backends/jerasure/jerasure_rs_vand.c | |||
@@ -56,11 +56,15 @@ typedef int (*jerasure_matrix_decode_func)(int, int, int, int *, int, int*, char | |||
56 | typedef int (*jerasure_make_decoding_matrix_func)(int, int, int, int *, int *, int *, int *); | 56 | typedef int (*jerasure_make_decoding_matrix_func)(int, int, int, int *, int *, int *, int *); |
57 | typedef int * (*jerasure_erasures_to_erased_func)(int, int, int *); | 57 | typedef int * (*jerasure_erasures_to_erased_func)(int, int, int *); |
58 | typedef void (*jerasure_matrix_dotprod_func)(int, int, int *,int *, int,char **, char **, int); | 58 | typedef void (*jerasure_matrix_dotprod_func)(int, int, int *,int *, int,char **, char **, int); |
59 | typedef void (*galois_uninit_field_func)(int); | ||
59 | 60 | ||
60 | struct jerasure_rs_vand_descriptor { | 61 | struct jerasure_rs_vand_descriptor { |
61 | /* calls required for init */ | 62 | /* calls required for init */ |
62 | reed_sol_vandermonde_coding_matrix_func reed_sol_vandermonde_coding_matrix; | 63 | reed_sol_vandermonde_coding_matrix_func reed_sol_vandermonde_coding_matrix; |
63 | 64 | ||
65 | /* calls required for free */ | ||
66 | galois_uninit_field_func galois_uninit_field; | ||
67 | |||
64 | /* calls required for encode */ | 68 | /* calls required for encode */ |
65 | jerasure_matrix_encode_func jerasure_matrix_encode; | 69 | jerasure_matrix_encode_func jerasure_matrix_encode; |
66 | 70 | ||
@@ -235,6 +239,7 @@ static void * jerasure_rs_vand_init(struct ec_backend_args *args, | |||
235 | */ | 239 | */ |
236 | union { | 240 | union { |
237 | reed_sol_vandermonde_coding_matrix_func initp; | 241 | reed_sol_vandermonde_coding_matrix_func initp; |
242 | galois_uninit_field_func uninitp; | ||
238 | jerasure_matrix_encode_func encodep; | 243 | jerasure_matrix_encode_func encodep; |
239 | jerasure_matrix_decode_func decodep; | 244 | jerasure_matrix_decode_func decodep; |
240 | jerasure_make_decoding_matrix_func decodematrixp; | 245 | jerasure_make_decoding_matrix_func decodematrixp; |
@@ -287,6 +292,13 @@ static void * jerasure_rs_vand_init(struct ec_backend_args *args, | |||
287 | goto error; | 292 | goto error; |
288 | } | 293 | } |
289 | 294 | ||
295 | func_handle.vptr = NULL; | ||
296 | func_handle.vptr = dlsym(backend_sohandle, "galois_uninit_field"); | ||
297 | desc->galois_uninit_field = func_handle.uninitp; | ||
298 | if (NULL == desc->galois_uninit_field) { | ||
299 | goto error; | ||
300 | } | ||
301 | |||
290 | desc->matrix = desc->reed_sol_vandermonde_coding_matrix( | 302 | desc->matrix = desc->reed_sol_vandermonde_coding_matrix( |
291 | desc->k, desc->m, desc->w); | 303 | desc->k, desc->m, desc->w); |
292 | if (NULL == desc->matrix) { | 304 | if (NULL == desc->matrix) { |
@@ -323,6 +335,16 @@ static int jerasure_rs_vand_exit(void *desc) | |||
323 | struct jerasure_rs_vand_descriptor *jerasure_desc = NULL; | 335 | struct jerasure_rs_vand_descriptor *jerasure_desc = NULL; |
324 | 336 | ||
325 | jerasure_desc = (struct jerasure_rs_vand_descriptor*) desc; | 337 | jerasure_desc = (struct jerasure_rs_vand_descriptor*) desc; |
338 | |||
339 | /* | ||
340 | * jerasure allocates some internal data structures for caching | ||
341 | * fields. It will allocate one for w, and if we do anything that | ||
342 | * needs to xor a region >= 16 bytes, it will also allocate one | ||
343 | * for 32. Fortunately we can safely uninit any value; if it | ||
344 | * wasn't inited it will be ignored. | ||
345 | */ | ||
346 | jerasure_desc->galois_uninit_field(jerasure_desc->w); | ||
347 | jerasure_desc->galois_uninit_field(32); | ||
326 | free(jerasure_desc->matrix); | 348 | free(jerasure_desc->matrix); |
327 | free(jerasure_desc); | 349 | free(jerasure_desc); |
328 | 350 | ||