diff --git a/libctf/ChangeLog b/libctf/ChangeLog index a7a31e70fc1..9e8129a610e 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,3 +1,8 @@ +2020-07-22 Nick Alcock + + * 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 * ctf-inlines.h: New file. diff --git a/libctf/ctf-hash.c b/libctf/ctf-hash.c index 4696fcb2d43..1c37d7515b4 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; }