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:
parent
a01b1818c8
commit
5afed81193
@ -26,9 +26,11 @@
|
|||||||
#define _ALG_SIG_H
|
#define _ALG_SIG_H
|
||||||
|
|
||||||
typedef int (*galois_single_multiply_func)(int, int, int);
|
typedef int (*galois_single_multiply_func)(int, int, int);
|
||||||
|
typedef void (*galois_uninit_field_func)(int);
|
||||||
|
|
||||||
struct jerasure_mult_routines {
|
struct jerasure_mult_routines {
|
||||||
galois_single_multiply_func galois_single_multiply;
|
galois_single_multiply_func galois_single_multiply;
|
||||||
|
galois_uninit_field_func galois_uninit_field;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__MACOS__) || defined(__MACOSX__) || defined(__OSX__) || defined(__APPLE__)
|
#if defined(__MACOS__) || defined(__MACOSX__) || defined(__OSX__) || defined(__APPLE__)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#define GALOIS_SINGLE_MULTIPLY "galois_single_multiply"
|
#define GALOIS_SINGLE_MULTIPLY "galois_single_multiply"
|
||||||
|
#define GALOIS_UNINIT "galois_uninit_field"
|
||||||
|
|
||||||
int valid_gf_w[] = { 8, 16, -1 };
|
int valid_gf_w[] = { 8, 16, -1 };
|
||||||
int valid_pairs[][2] = { { 8, 32}, {16, 32}, {16, 64}, {-1, -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;
|
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()
|
void *get_jerasure_sohandle()
|
||||||
{
|
{
|
||||||
return dlopen(JERASURE_SONAME, RTLD_LAZY | RTLD_LOCAL);
|
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)
|
int load_gf_functions(void *sohandle, struct jerasure_mult_routines *routines)
|
||||||
{
|
{
|
||||||
routines->galois_single_multiply = get_galois_multi_func(sohandle);
|
routines->galois_single_multiply = get_galois_multi_func(sohandle);
|
||||||
|
routines->galois_uninit_field = get_galois_uninit_func(sohandle);
|
||||||
if (NULL == routines->galois_single_multiply) {
|
if (NULL == routines->galois_single_multiply) {
|
||||||
return -1;
|
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_l = (int*)malloc(sizeof(int) * num_gf_lr_table_syms);
|
||||||
alg_sig_handle->tbl1_r = (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) {
|
if (num_components >= 4) {
|
||||||
alg_sig_handle->tbl2_l = (int*)malloc(sizeof(int) * num_gf_lr_table_syms);
|
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);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alg_sig_handle->mult_routines.galois_uninit_field(alg_sig_handle->gf_w);
|
||||||
dlclose(alg_sig_handle->jerasure_sohandle);
|
dlclose(alg_sig_handle->jerasure_sohandle);
|
||||||
|
|
||||||
int num_components = alg_sig_handle->sig_len / alg_sig_handle->gf_w;
|
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_l);
|
||||||
free(alg_sig_handle->tbl3_r);
|
free(alg_sig_handle->tbl3_r);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(alg_sig_handle);
|
free(alg_sig_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user