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.
This commit is contained in:
Allison Karlitskaya 2019-05-20 16:39:35 +02:00
parent b3fbf6c18b
commit 9add93e5a4

View File

@ -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++)