1
Fork 0

Revert "Fix memory leak problem for bmz8"

This code leaks memory when iterations reaches 0 and previous code was
correct. See https://sourceforge.net/p/cmph/git/merge-requests/4/.
This commit is contained in:
Davi Reis 2014-06-06 12:33:04 -03:00
parent c09a1f64ea
commit 217c784dda
1 changed files with 5 additions and 9 deletions

View File

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