fix(hash_map): fixed leak on value update

This commit is contained in:
william.valenduc 2026-01-19 15:28:35 +00:00
parent 3cf1960a00
commit 2ebf56dde7
4 changed files with 251 additions and 13 deletions

View file

@ -19,10 +19,23 @@ struct hash_map
struct hash_map *hash_map_init(size_t size);
/**
* @brief Inserts a key-value pair into the hash map. Key and value are expected
* to be on the heap and will be managed by the hash map. It means they are
* consumed by this function. If the key already exists, its value is updated
* and the key is not consumed so it must be freed by the caller.
*
* @param hash_map The hash map.
* @param key The key to insert.
* @param value The value to insert.
* @param updated If not NULL, set to true if the key was already present and
* updated, false if the key was newly inserted.
* @return true on success, false on failure.
*/
bool hash_map_insert(struct hash_map *hash_map, const char *key, void *value,
bool *updated);
void hash_map_free(struct hash_map *hash_map);
void hash_map_free(struct hash_map **hash_map);
void hash_map_foreach(struct hash_map *hash_map,
void (*fn)(const char *, const void *));