Although the hash table implementation allows passing a callback function
to free a value when it is removed from the hash table, hash_del() wasn't
freeing it if it was provided. Now it does.
As a bonus, it now checks if the callback is set in hash_add() as well.
for (; entry < entry_end; entry++) {
int c = strcmp(key, entry->key);
if (c == 0) {
- hash->free_value((void *)entry->value);
+ if (hash->free_value)
+ hash->free_value((void *)entry->value);
entry->value = value;
return 0;
} else if (c < 0) {
if (entry == NULL)
return -ENOENT;
+ if (hash->free_value)
+ hash->free_value((void *)entry->value);
+
entry_end = bucket->entries + bucket->used;
memmove(entry, entry + 1,
(entry_end - entry) * sizeof(struct hash_entry));