From cf5da6f231da6bb92ee280dc7bfcfbdc6b3cd152 Mon Sep 17 00:00:00 2001 From: "william.valenduc" Date: Sat, 17 Jan 2026 23:57:59 +0000 Subject: [PATCH] feat(hash_map): destroy_pair_list --- src/utils/hash_map/hash_map.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/hash_map/hash_map.c b/src/utils/hash_map/hash_map.c index dec698c..46ac9d1 100644 --- a/src/utils/hash_map/hash_map.c +++ b/src/utils/hash_map/hash_map.c @@ -28,6 +28,14 @@ static size_t hash(const char *key) return hash; } +static void destroy_pair_list(struct pair_list **p) +{ + free((char *)(*p)->key); + free((*p)->value); + free((*p)); + *p = NULL; +} + struct hash_map *hash_map_init(size_t size) { struct hash_map *p = malloc(sizeof(struct hash_map)); @@ -102,7 +110,7 @@ void hash_map_free(struct hash_map *hash_map) { prev = l; l = l->next; - free(prev); + destroy_pair_list(&prev); } } free(hash_map->data); @@ -163,7 +171,7 @@ bool hash_map_remove(struct hash_map *hash_map, const char *key) p->next = l->next; else hash_map->data[i] = l->next; - free(l); + destroy_pair_list(&l); return true; } p = l;