File dhcpv6-1.0.22-memleak-fix of Package dhcpv6
From: Jeff Mahoney <jeffm@suse.com>
Subject: dhcpv6: fix memory leak in hash creation
References: bnc#535107
If there is a collision after allocating a hash node, it
returns HASH_COLLISION without freeing the node.
This patch frees it properly.
---
src/hash.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--- a/src/hash.c
+++ b/src/hash.c
@@ -68,8 +68,8 @@ struct hash_table *hash_table_create(uns
int hash_add(struct hash_table *hash_tbl, const void *key, void *data) {
int index;
struct hashlist_element *element;
- element =
- (struct hashlist_element *) malloc(sizeof(struct hashlist_element));
+
+ element = (struct hashlist_element *) malloc(sizeof(*element));
if (!element) {
dhcpv6_dprintf(LOG_ERR, "Could not malloc hashlist_element");
return (-1);
@@ -80,6 +80,7 @@ int hash_add(struct hash_table *hash_tbl
index = hash_tbl->hash_function(key) % hash_tbl->hash_size;
if (hash_search(hash_tbl, key)) {
dhcpv6_dprintf(LOG_DEBUG, "hash_add: duplicated item");
+ free(element);
return HASH_COLLISION;
}
element->next = hash_tbl->hash_list[index];