From 217c784dda7a8d8d08d55321e535429920edda01 Mon Sep 17 00:00:00 2001 From: Davi Reis Date: Fri, 6 Jun 2014 12:33:04 -0300 Subject: [PATCH] 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/. --- src/bmz8.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/bmz8.c b/src/bmz8.c index 55a34f5..894463d 100644 --- a/src/bmz8.c +++ b/src/bmz8.c @@ -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) {