hashmap: honor the value destructor in set_ensure_consume()

Sets store their element in the key slot but use a value destructor
(DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR). On the reject/duplicate path
set_ensure_consume() only checked free_key and otherwise called free().

Follow-up for fcc1d0315d
This commit is contained in:
Luca Boccassi
2026-07-06 13:42:21 +01:00
parent 2f72db10d9
commit 87e57c52c1
2 changed files with 45 additions and 0 deletions
+3
View File
@@ -1330,6 +1330,9 @@ int set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key) {
if (r <= 0) {
if (hash_ops && hash_ops->free_key)
hash_ops->free_key(key);
else if (hash_ops && hash_ops->free_value)
/* Sets store their element in the key slot but may carry a value destructor. */
hash_ops->free_value(key);
else
free(key);
}