hashmap: rework hashmap_clear() to be more defensive

Let's first remove an item from the hashmap and only then destroy it.
This makes sure that destructor functions can mdoify the hashtables in
their own codee and we won't be confused by that.
This commit is contained in:
Lennart Poettering
2018-12-18 11:28:10 +01:00
parent 1a126325eb
commit c380b84d8b
2 changed files with 19 additions and 11 deletions
+5 -1
View File
@@ -191,7 +191,11 @@ static inline void *ordered_hashmap_remove2(OrderedHashmap *h, const void *key,
return hashmap_remove2(PLAIN_HASHMAP(h), key, rkey);
}
void *hashmap_remove_value(Hashmap *h, const void *key, void *value);
void *internal_hashmap_remove_value(HashmapBase *h, const void *key, void *value);
static inline void *hashmap_remove_value(Hashmap *h, const void *key, void *value) {
return internal_hashmap_remove_value(HASHMAP_BASE(h), key, value);
}
static inline void *ordered_hashmap_remove_value(OrderedHashmap *h, const void *key, void *value) {
return hashmap_remove_value(PLAIN_HASHMAP(h), key, value);
}