summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllison Karlitskaya <allison.karlitskaya@redhat.com>2019-05-20 16:39:35 +0200
committerAllison Karlitskaya <allison.karlitskaya@redhat.com>2019-05-20 17:03:49 +0200
commit9add93e5a4679a38c311893c7e08c75efc242bd1 (patch)
tree72db826845c0ab1e1b00fc29f92b1a70cf23f5e3
parentb3fbf6c18ba35bd5210d2c08f035f3516bb668aa (diff)
downloadglib-9add93e5a4679a38c311893c7e08c75efc242bd1.tar.gz
ghash: Be more explicit about memory in g_hash_table_destroy_all_nodes()
Make it clear that there is a reference transfer going on here, rather than relying on the fields being overwritten on each branch of the conditional below.
-rw-r--r--glib/ghash.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/glib/ghash.c b/glib/ghash.c
index 14932cba7..b21d00ff9 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -637,9 +637,9 @@ g_hash_table_remove_all_nodes (GHashTable *hash_table,
* freeing them below.
*/
old_size = hash_table->size;
- old_keys = hash_table->keys;
- old_values = hash_table->values;
- old_hashes = hash_table->hashes;
+ old_keys = g_steal_pointer (&hash_table->keys);
+ old_values = g_steal_pointer (&hash_table->values);
+ old_hashes = g_steal_pointer (&hash_table->hashes);
if (!destruction)
/* Any accesses will see an empty table */
@@ -651,12 +651,7 @@ g_hash_table_remove_all_nodes (GHashTable *hash_table,
}
else
/* Will cause a quick crash on any attempted access */
- {
- hash_table->size = hash_table->mod = hash_table->mask = 0;
- hash_table->keys = NULL;
- hash_table->values = NULL;
- hash_table->hashes = NULL;
- }
+ hash_table->size = hash_table->mod = hash_table->mask = 0;
/* Now do the actual destroy notifies */
for (i = 0; i < old_size; i++)