diff options
author | Kevin Greenan <kmg@box.com> | 2015-04-27 11:34:54 -0700 |
---|---|---|
committer | Kevin Greenan <kmg@box.com> | 2015-04-27 11:59:32 -0700 |
commit | 5afed811936994cee54f923e5d69174bd14a5bb7 (patch) | |
tree | 7f9b99709e927b6327971f211d98d1c5b6ea6bbf | |
parent | a01b1818c874a65d1d1fb8f11ea441e9d3e18771 (diff) | |
download | liberasurecode-5afed811936994cee54f923e5d69174bd14a5bb7.tar.gz |
This fixed the memory leak mentioned in Issue #12:
https://bitbucket.org/tsg-/liberasurecode/issue/12/make-valgrind-test-fails
-rw-r--r-- | include/erasurecode/alg_sig.h | 2 | ||||
-rw-r--r-- | src/utils/chksum/alg_sig.c | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/include/erasurecode/alg_sig.h b/include/erasurecode/alg_sig.h index 373328d..52554a9 100644 --- a/include/erasurecode/alg_sig.h +++ b/include/erasurecode/alg_sig.h @@ -26,9 +26,11 @@ #define _ALG_SIG_H typedef int (*galois_single_multiply_func)(int, int, int); +typedef void (*galois_uninit_field_func)(int); struct jerasure_mult_routines { galois_single_multiply_func galois_single_multiply; + galois_uninit_field_func galois_uninit_field; }; #if defined(__MACOS__) || defined(__MACOSX__) || defined(__OSX__) || defined(__APPLE__) diff --git a/src/utils/chksum/alg_sig.c b/src/utils/chksum/alg_sig.c index 07a9683..9dd7a27 100644 --- a/src/utils/chksum/alg_sig.c +++ b/src/utils/chksum/alg_sig.c @@ -28,6 +28,7 @@ #include <stdlib.h> #include <string.h> #define GALOIS_SINGLE_MULTIPLY "galois_single_multiply" +#define GALOIS_UNINIT "galois_uninit_field" int valid_gf_w[] = { 8, 16, -1 }; int valid_pairs[][2] = { { 8, 32}, {16, 32}, {16, 64}, {-1, -1} }; @@ -46,6 +47,21 @@ galois_single_multiply_func get_galois_multi_func(void *handle) { return func_handle.fptr; } +galois_uninit_field_func get_galois_uninit_func(void *handle) { + /* + * ISO C forbids casting a void* to a function pointer. + * Since dlsym return returns a void*, we use this union to + * "transform" the void* to a function pointer. + */ + union { + galois_uninit_field_func fptr; + void *vptr; + } func_handle = {.vptr = NULL}; + func_handle.vptr = dlsym(handle, GALOIS_UNINIT); + return func_handle.fptr; +} + + void *get_jerasure_sohandle() { return dlopen(JERASURE_SONAME, RTLD_LAZY | RTLD_LOCAL); @@ -54,6 +70,7 @@ void *get_jerasure_sohandle() int load_gf_functions(void *sohandle, struct jerasure_mult_routines *routines) { routines->galois_single_multiply = get_galois_multi_func(sohandle); + routines->galois_uninit_field = get_galois_uninit_func(sohandle); if (NULL == routines->galois_single_multiply) { return -1; } @@ -152,7 +169,7 @@ alg_sig_t *init_alg_sig_w16(void *jerasure_sohandle, int sig_len) alg_sig_handle->tbl1_l = (int*)malloc(sizeof(int) * num_gf_lr_table_syms); alg_sig_handle->tbl1_r = (int*)malloc(sizeof(int) * num_gf_lr_table_syms); } - + if (num_components >= 4) { alg_sig_handle->tbl2_l = (int*)malloc(sizeof(int) * num_gf_lr_table_syms); alg_sig_handle->tbl2_r = (int*)malloc(sizeof(int) * num_gf_lr_table_syms); @@ -221,6 +238,7 @@ void destroy_alg_sig(alg_sig_t* alg_sig_handle) return; } + alg_sig_handle->mult_routines.galois_uninit_field(alg_sig_handle->gf_w); dlclose(alg_sig_handle->jerasure_sohandle); int num_components = alg_sig_handle->sig_len / alg_sig_handle->gf_w; @@ -233,6 +251,7 @@ void destroy_alg_sig(alg_sig_t* alg_sig_handle) free(alg_sig_handle->tbl3_l); free(alg_sig_handle->tbl3_r); } + free(alg_sig_handle); } |