From 9add93e5a4679a38c311893c7e08c75efc242bd1 Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Mon, 20 May 2019 16:39:35 +0200 Subject: [PATCH] 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. --- glib/ghash.c | 13 ++++--------- 1 file 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++)