All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hashmap: Entry pointers were not freed when map was destroyed
@ 2015-01-13 12:56 Jukka Rissanen
  2015-01-16  5:43 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Jukka Rissanen @ 2015-01-13 12:56 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]

The l_hashmap_destroy() did not free the left over entry pointers
that were allocated in l_hashmap_insert(). If user did not remove
them by calling the l_hashmap_remove(), then the entries were left
in the hash which caused a memory leak.
---
 ell/hashmap.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/ell/hashmap.c b/ell/hashmap.c
index 8cfe421..b60cc62 100644
--- a/ell/hashmap.c
+++ b/ell/hashmap.c
@@ -322,18 +322,23 @@ LIB_EXPORT void l_hashmap_destroy(struct l_hashmap *hashmap,
 		return;
 
 	for (i = 0; i < NBUCKETS; i++) {
-		struct entry *entry, *head = &hashmap->buckets[i];
+		struct entry *entry, *next, *head = &hashmap->buckets[i];
 
 		if (!head->next)
 			continue;
 
-		for (entry = head;; entry = entry->next) {
+		for (entry = head;; entry = next) {
 			if (destroy)
 				destroy(entry->value);
 
 			free_key(hashmap, entry->key);
 
-			if (entry->next == head)
+			next = entry->next;
+
+			if (entry != head)
+				l_free(entry);
+
+			if (next == head)
 				break;
 		}
 	}
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hashmap: Entry pointers were not freed when map was destroyed
  2015-01-13 12:56 [PATCH] hashmap: Entry pointers were not freed when map was destroyed Jukka Rissanen
@ 2015-01-16  5:43 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2015-01-16  5:43 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 469 bytes --]

Hi Jukka,

On 01/13/2015 06:56 AM, Jukka Rissanen wrote:
> The l_hashmap_destroy() did not free the left over entry pointers
> that were allocated in l_hashmap_insert(). If user did not remove
> them by calling the l_hashmap_remove(), then the entries were left
> in the hash which caused a memory leak.
> ---
>   ell/hashmap.c | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
>

Patch has been applied, thanks.

Regards,
-Denis



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-16  5:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-13 12:56 [PATCH] hashmap: Entry pointers were not freed when map was destroyed Jukka Rissanen
2015-01-16  5:43 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.