summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-04-26 11:39:46 +0200
committerJo-Philipp Wich <jo@mein.io>2021-04-26 11:57:56 +0200
commitc51934a9ab7d416b5ef25c28efd2cf693c4c1f3a (patch)
treeb71f6b7fcdbb56a2b0e4b79aefcdc825553b869c
parent7b287279d933e69168b99a643ecb91631fd4f992 (diff)
types: fix potential leak of key in ucv_object_add()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--types.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/types.c b/types.c
index de2860f..85023c6 100644
--- a/types.c
+++ b/types.c
@@ -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);