This fixed the memory leak mentioned in Issue #12:

https://bitbucket.org/tsg-/liberasurecode/issue/12/make-valgrind-test-fails
This commit is contained in:
Kevin Greenan 2015-04-27 11:34:54 -07:00
parent a01b1818c8
commit 5afed81193
2 changed files with 22 additions and 1 deletions

View File

@ -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__)

View File

@ -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);
}