diff --git a/include/alg_sig.h b/include/alg_sig.h index fee0156..f838d7b 100644 --- a/include/alg_sig.h +++ b/include/alg_sig.h @@ -40,6 +40,7 @@ typedef struct alg_sig_s } alg_sig_t; alg_sig_t *init_alg_sig(int sig_len, int gf_w); +void destroy_alg_sig(alg_sig_t* alg_sig_handle); int compute_alg_sig(alg_sig_t* alg_sig_handle, char *buf, int len, char *sig); int crc32_build_fast_table(); diff --git a/src/alg_sig.c b/src/alg_sig.c index 2170761..02478b0 100644 --- a/src/alg_sig.c +++ b/src/alg_sig.c @@ -156,6 +156,29 @@ alg_sig_t *init_alg_sig(int sig_len, int gf_w) return NULL; } +void destroy_alg_sig(alg_sig_t* alg_sig_handle) +{ + if (alg_sig_handle == NULL) { + return; + } + if (alg_sig_handle->gf_w == 0) { + free(alg_sig_handle); + return; + } + int num_components = alg_sig_handle->sig_len / alg_sig_handle->gf_w; + + free(alg_sig_handle->tbl1_l); + free(alg_sig_handle->tbl1_r); + if (num_components >= 4) { + free(alg_sig_handle->tbl2_l); + free(alg_sig_handle->tbl2_r); + free(alg_sig_handle->tbl3_l); + free(alg_sig_handle->tbl3_r); + } + free(alg_sig_handle); +} + + static int compute_w8_alg_sig_32(alg_sig_t *alg_sig_handle, char *buf, int len, char *sig) { diff --git a/tests/alg_sig_test.c b/tests/alg_sig_test.c index 940149e..4f1c5df 100644 --- a/tests/alg_sig_test.c +++ b/tests/alg_sig_test.c @@ -123,6 +123,7 @@ static int basic_xor_test_8_32() free(sigs[num_data]); free(sigs); free(data); + destroy_alg_sig(sig_handle); return ret; } @@ -168,6 +169,7 @@ static int basic_xor_test_16_64() free(sigs[num_data]); free(sigs); free(data); + destroy_alg_sig(sig_handle); return ret; @@ -215,6 +217,7 @@ static int basic_xor_test_16_32() free(sigs[num_data]); free(sigs); free(data); + destroy_alg_sig(sig_handle); return ret; }