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-25 18:02:12 +0200
commitde21f49cda5554d1395d315c022c2f28d06ba778 (patch)
treebcf2e24feed548e38cc2c63b062ad42955ad2ae0
parent22f044e197cb3c3ce9b1e19972bfd95eb0d53d82 (diff)
downloadlibrest-de21f49cda5554d1395d315c022c2f28d06ba778.tar.gz
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
-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);
}
/**