diff --git a/src/bmz8.c b/src/bmz8.c index 894463d..55a34f5 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 **)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; do @@ -101,18 +101,22 @@ 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) { diff --git a/src/fch.c b/src/fch.c index a37164e..ae3226c 100644 --- a/src/fch.c +++ b/src/fch.c @@ -264,12 +264,12 @@ cmph_t *fch_new(cmph_config_t *mph, double c) fch->h2 = NULL; fch->g = NULL; do - { + { if (mph->verbosity) { fprintf(stderr, "Entering mapping step for mph creation of %u keys\n", fch->m); } - if (buckets) fch_buckets_destroy(buckets); + if (buckets) fch_buckets_destroy(buckets, mph); buckets = mapping(mph); if (mph->verbosity) { @@ -285,7 +285,7 @@ cmph_t *fch_new(cmph_config_t *mph, double c) iterations--; } while(restart_mapping && iterations > 0); - if (buckets) fch_buckets_destroy(buckets); + if (buckets) fch_buckets_destroy(buckets, mph); if (sorted_indexes) free (sorted_indexes); if (iterations == 0) return NULL; mphf = (cmph_t *)malloc(sizeof(cmph_t)); diff --git a/src/fch_buckets.c b/src/fch_buckets.c index 88074c7..db8f6f4 100644 --- a/src/fch_buckets.c +++ b/src/fch_buckets.c @@ -1,5 +1,6 @@ #include "vqueue.h" #include "fch_buckets.h" +#include "cmph_structs.h" #include #include #include @@ -28,13 +29,14 @@ static void fch_bucket_new(fch_bucket_t *bucket) bucket->capacity = 0; } -static void fch_bucket_destroy(fch_bucket_t *bucket) +static void fch_bucket_destroy(fch_bucket_t *bucket, cmph_config_t *mph) { cmph_uint32 i; assert(bucket); for (i = 0; i < bucket->size; i++) { - free((bucket->entries + i)->value); + fch_bucket_entry_t * entry = bucket->entries + i; + mph->key_source->dispose(mph->key_source->data, entry->value, entry->length); } free(bucket->entries); } @@ -205,10 +207,10 @@ void fch_buckets_print(fch_buckets_t * buckets) for (i = 0; i < buckets->nbuckets; i++) fch_bucket_print(buckets->values + i, i); } -void fch_buckets_destroy(fch_buckets_t * buckets) +void fch_buckets_destroy(fch_buckets_t * buckets, cmph_config_t *mph) { cmph_uint32 i; - for (i = 0; i < buckets->nbuckets; i++) fch_bucket_destroy(buckets->values + i); + for (i = 0; i < buckets->nbuckets; i++) fch_bucket_destroy(buckets->values + i, mph); free(buckets->values); free(buckets); } diff --git a/src/fch_buckets.h b/src/fch_buckets.h index 2a1b8b2..10e97af 100644 --- a/src/fch_buckets.h +++ b/src/fch_buckets.h @@ -2,6 +2,7 @@ #define __CMPH_FCH_BUCKETS_H__ #include "cmph_types.h" +#include "cmph.h" typedef struct __fch_buckets_t fch_buckets_t; fch_buckets_t * fch_buckets_new(cmph_uint32 nbuckets); @@ -26,5 +27,5 @@ cmph_uint32 * fch_buckets_get_indexes_sorted_by_size(fch_buckets_t * buckets); void fch_buckets_print(fch_buckets_t * buckets); -void fch_buckets_destroy(fch_buckets_t * buckets); +void fch_buckets_destroy(fch_buckets_t * buckets, cmph_config_t* mph); #endif