diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-04-26 11:39:46 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-04-26 11:57:56 +0200 |
commit | c51934a9ab7d416b5ef25c28efd2cf693c4c1f3a (patch) | |
tree | b71f6b7fcdbb56a2b0e4b79aefcdc825553b869c | |
parent | 7b287279d933e69168b99a643ecb91631fd4f992 (diff) |
types: fix potential leak of key in ucv_object_add()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | types.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -779,6 +779,7 @@ ucv_object_add(uc_value_t *uv, const char *key, uc_value_t *val) struct lh_entry *existing_entry; uc_value_t *existing_value; unsigned long hash; + void *k; if (ucv_type(uv) != UC_OBJECT) return false; @@ -787,7 +788,15 @@ ucv_object_add(uc_value_t *uv, const char *key, uc_value_t *val) existing_entry = lh_table_lookup_entry_w_hash(object->table, (const void *)key, hash); if (existing_entry == NULL) { - return (lh_table_insert_w_hash(object->table, xstrdup(key), val, hash, 0) == 0); + k = xstrdup(key); + + if (lh_table_insert_w_hash(object->table, k, val, hash, 0) != 0) { + free(k); + + return false; + } + + return true; } existing_value = (uc_value_t *)lh_entry_v(existing_entry); |