diff options
-rw-r--r-- | libctf/ChangeLog | 5 | ||||
-rw-r--r-- | libctf/ctf-hash.c | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/libctf/ChangeLog b/libctf/ChangeLog index a7a31e7..9e8129a 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,5 +1,10 @@ 2020-07-22 Nick Alcock <nick.alcock@oracle.com> + * ctf-hash.c (ctf_hashtab_insert): Free the key passed in if + there is a key-freeing function and the key already exists. + +2020-07-22 Nick Alcock <nick.alcock@oracle.com> + * ctf-inlines.h: New file. * ctf-impl.h: Include it. (ctf_hash_iter_find_f): New typedef. diff --git a/libctf/ctf-hash.c b/libctf/ctf-hash.c index 4696fcb..1c37d75 100644 --- a/libctf/ctf-hash.c +++ b/libctf/ctf-hash.c @@ -171,15 +171,15 @@ ctf_hashtab_insert (struct htab *htab, void *key, void *value, *slot = malloc (sizeof (ctf_helem_t)); if (!*slot) return NULL; + (*slot)->key = key; } else { if (key_free) - key_free ((*slot)->key); + key_free (key); if (value_free) value_free ((*slot)->value); } - (*slot)->key = key; (*slot)->value = value; return *slot; } |