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;