Skip to contentSkip to conversation

hashmap: Fix removing last entry in l_hashmap_foreach_remove

PATCH In review Andrew Zaborowski 2 participants 2 messages Oct 20, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hashmap: Fix removing last entry in l_hashmap_foreach_remove

When the last entry in a bucket with 2 or more entries was removed the loop would roll over and iterate over the remaining entries for a second time (then stop), add missing check.

---
 ell/hashmap.c | 2 ++
 1 file changed, 2 insertions(+)
ell/hashmap.c +2 -0
index ee11d31..061080b 100644
@@ -607,6 +607,8 @@ LIB_EXPORT unsigned int l_hashmap_foreach_remove(struct l_hashmap *hashmap,
 				free_key(hashmap, entry->key);
 				l_free(entry);
 				entry = prev->next;
+				if (entry == head)
+					break;
 				continue;
 			}
 
Signature · 1 line
2.19.1
#1 lore raw

Hi Andrew,

Quoted 7 lines · Andrew Zaborowski

When the last entry in a bucket with 2 or more entries was removed the loop would roll over and iterate over the remaining entries for a second time (then stop), add missing check.

---
  ell/hashmap.c | 2 ++
  1 file changed, 2 insertions(+)

Hah, good catch. Applied, thanks.

Regards,
-Denis