From 2d52f0e2c9ec84bb9cfbf21d31f0496752d94d4d Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Wed, 29 Sep 2010 10:05:30 +0200 Subject: [PATCH 2/3] dhash: Fix memory leak in example --- dhash/examples/dhash_example.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/dhash/examples/dhash_example.c b/dhash/examples/dhash_example.c index bd0ca8e..c7eac3d 100644 --- a/dhash/examples/dhash_example.c +++ b/dhash/examples/dhash_example.c @@ -81,6 +81,7 @@ int main(int argc, char **argv) fprintf(stderr, "cannot add to table \"%s\" (%s)\n", key.str, hash_error_string(error)); return error; } + free(key.str); /* Get a list of keys and print them out, free the list when we're done */ if ((error = hash_keys(table, &count, &keys)) != HASH_SUCCESS) { @@ -98,6 +99,7 @@ int main(int argc, char **argv) if ((error = hash_lookup(table, &key, &value)) != HASH_SUCCESS) { fprintf(stderr, "cannot find key \"%s\" (%s)\n", key.str, hash_error_string(error)); } + free(key.str); /* Visit each entry in the table, callback will increment count on each visit */ printf("Iterate using callback\n"); @@ -130,6 +132,7 @@ int main(int argc, char **argv) /* Assure key is no longer in table */ assert (!hash_has_key(table, &key)); + free(key.str); /* Free the table */ hash_destroy(table); -- 1.7.2.3