Fix memory leak problem for bmz8

This commit is contained in:
Huang-Ming Huang 2014-05-23 08:55:22 -05:00
parent 2cf5c15cf6
commit a45235f886

View File

@ -84,7 +84,7 @@ cmph_t *bmz8_new(cmph_config_t *mph, double c)
bmz8->graph = graph_new(bmz8->n, bmz8->m); bmz8->graph = graph_new(bmz8->n, bmz8->m);
DEBUGP("Created graph\n"); DEBUGP("Created graph\n");
bmz8->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*3); bmz8->hashes = (hash_state_t **)calloc(3,sizeof(hash_state_t *));
for(i = 0; i < 3; ++i) bmz8->hashes[i] = NULL; for(i = 0; i < 3; ++i) bmz8->hashes[i] = NULL;
do do
@ -101,18 +101,22 @@ cmph_t *bmz8_new(cmph_config_t *mph, double c)
{ {
int ok; int ok;
DEBUGP("hash function 1\n"); DEBUGP("hash function 1\n");
if (bmz8->hashes[0])
hash_state_destroy(bmz8->hashes[0]);
bmz8->hashes[0] = hash_state_new(bmz8->hashfuncs[0], bmz8->n); bmz8->hashes[0] = hash_state_new(bmz8->hashfuncs[0], bmz8->n);
DEBUGP("hash function 2\n"); DEBUGP("hash function 2\n");
if (bmz8->hashes[1])
bmz8->hashes[1] = NULL;
bmz8->hashes[1] = hash_state_new(bmz8->hashfuncs[1], bmz8->n); bmz8->hashes[1] = hash_state_new(bmz8->hashfuncs[1], bmz8->n);
DEBUGP("Generating edges\n"); DEBUGP("Generating edges\n");
ok = bmz8_gen_edges(mph); ok = bmz8_gen_edges(mph);
if (!ok) if (!ok)
{ {
--iterations; --iterations;
hash_state_destroy(bmz8->hashes[0]); // hash_state_destroy(bmz8->hashes[0]);
bmz8->hashes[0] = NULL; // bmz8->hashes[0] = NULL;
hash_state_destroy(bmz8->hashes[1]); // hash_state_destroy(bmz8->hashes[1]);
bmz8->hashes[1] = NULL; // bmz8->hashes[1] = NULL;
DEBUGP("%u iterations remaining\n", iterations); DEBUGP("%u iterations remaining\n", iterations);
if (mph->verbosity) if (mph->verbosity)
{ {