summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2014-06-04 16:51:33 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2014-08-27 17:35:28 +0200
commitd007792758b84629ec67b431da8136fc0c51a023 (patch)
tree7f1a6f7077aa5a8f40b57c49fea8125be00d6cea
parentd8cf10043563bdc43bc9ef32d6faed1fe0ebfba1 (diff)
Use g_hash_table_replace() in rest_params_add()
rest_params_add() is currently using g_hash_table_insert() to add the passed in parameter in the parameter hash table. The key which is used is owned by the associated value. When using rest_params_add to replace an already existing parameter, the existing value will be freed with rest_param_unref(). However, g_hash_table_insert() does not replace the key when it already exists in the hash table: "If the key already exists in the GHashTable its current value is replaced with the new value... If you supplied a key_destroy_func when creating the GHashTable, the passed key is freed using that function." This means that after replacing an already existing parameter, the corresponding key will still be the old one, which is now pointing at freed memory as the old value was freed. g_hash_table_replace() ensures that the key will still be valid, even when replacing existing parameters: "Inserts a new key and value into a GHashTable similar to g_hash_table_insert(). The difference is that if the key already exists in the GHashTable, it gets replaced by the new key." https://bugzilla.gnome.org/show_bug.cgi?id=665716 (cherry picked from commit de21f49cda5554d1395d315c022c2f28d06ba778)
-rw-r--r--rest/rest-params.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/rest/rest-params.c b/rest/rest-params.c
index a5666fa..369215b 100644
--- a/rest/rest-params.c
+++ b/rest/rest-params.c
@@ -91,7 +91,7 @@ rest_params_add (RestParams *params, RestParam *param)
g_return_if_fail (params);
g_return_if_fail (param);
- g_hash_table_insert (hash, (gpointer)rest_param_get_name (param), param);
+ g_hash_table_replace (hash, (gpointer)rest_param_get_name (param), param);
}
/**