The following commit has been merged in the master branch: commit 9473ce3886270b9a97d821f0e424ac7918fb3eae Author: Simon Wunderlich siwu@hrz.tu-chemnitz.de Date: Sat Mar 10 13:50:08 2007 +0100
- split hash_delete and hash_destroy
diff --git a/batman.c b/batman.c index 6167373..f6bf964 100644 --- a/batman.c +++ b/batman.c @@ -854,7 +854,7 @@ int8_t batman() {
purge_orig( get_time() + ( 5 * TIMEOUT ) + orginator_interval );
- hash_delete( orig_hash ); + hash_destroy( orig_hash );
list_for_each_safe( hna_pos, hna_pos_tmp, &hna_list ) { diff --git a/hash.c b/hash.c index 84f7ffd..42c2bbc 100644 --- a/hash.c +++ b/hash.c @@ -35,7 +35,7 @@ void hash_init(struct hashtable_t *hash) { /* remove the hash structure. if hashdata_free_cb != NULL, * this function will be called to remove the elements inside of the hash. * if you don't remove the elements, memory might be leaked. */ -/*void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb) { +void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb) { struct element_t *bucket, *last_bucket; int i;
@@ -52,12 +52,13 @@ void hash_init(struct hashtable_t *hash) { } } } -}*/ + hash_destroy(hash); +}
-/* FYI: purge deletes all elements within that structure but we should free the hash itself !*/ -void hash_delete(struct hashtable_t *hash) { +/* free only the hashtable and the hash itself. */ +void hash_destroy(struct hashtable_t *hash) {
debugFree( hash->table, 1301 ); debugFree( hash, 1302 ); @@ -234,7 +235,8 @@ struct hashtable_t *hash_resize(struct hashtable_t *hash, int size) { } } } - hash_delete(hash); + hash_delete(hash, NULL ); /* remove hash and eventual overflow buckets, + * but not the content itself. */
return( new_hash);
diff --git a/hash.h b/hash.h index 71b4c8c..8052078 100644 --- a/hash.h +++ b/hash.h @@ -53,8 +53,10 @@ struct hashtable_t *hash_new(int size, hashdata_compare_cb compare, hashdata_cho /* remove the hash structure. if hashdata_free_cb != NULL, * this function will be called to remove the elements inside of the hash. * if you don't remove the elements, memory might be leaked. */ -void hash_delete(struct hashtable_t *hash); +void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb);
+/* free only the hashtable and the hash itself. */ +void hash_destroy(struct hashtable_t *hash);
/* adds data to the hashtable. returns 0 on success, -1 on error */ int hash_add(struct hashtable_t *hash, void *data);