From b3fbf6c18ba35bd5210d2c08f035f3516bb668aa Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Mon, 20 May 2019 16:36:31 +0200 Subject: [PATCH] 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. --- glib/ghash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glib/ghash.c b/glib/ghash.c index a7c0334bf..14932cba7 100644 --- a/glib/ghash.c +++ b/glib/ghash.c @@ -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;