ghash: do less work when destroying the table

We were calling g_hash_table_set_shift() to reinitialise the hash table
even in the case of destroying it.  Only do that for the non-destruction
case, and fill the relevant fields with zeros for the destruction case.
This has a nice side effect of causing more certain crashes in case of
invalid reuse of the table after (or during) destruction.
This commit is contained in:
Allison Karlitskaya 2019-05-20 16:36:31 +02:00
parent c5462cb3c1
commit b3fbf6c18b

View File

@ -641,10 +641,10 @@ g_hash_table_remove_all_nodes (GHashTable *hash_table,
old_values = hash_table->values;
old_hashes = hash_table->hashes;
g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
if (!destruction)
/* Any accesses will see an empty table */
{
g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
hash_table->keys = g_hash_table_realloc_key_or_value_array (NULL, hash_table->size, FALSE);
hash_table->values = hash_table->keys;
hash_table->hashes = g_new0 (guint, hash_table->size);
@ -652,6 +652,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;