[glib/glib-2-60: 3/6] ghash: do less work when destroying the table
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-60: 3/6] ghash: do less work when destroying the table
- Date: Tue, 21 May 2019 10:30:06 +0000 (UTC)
commit bef8b10c9648894cd4d38ea9961a76c48447a8c3
Author: Allison Karlitskaya <allison karlitskaya redhat com>
Date: Mon May 20 16:36:31 2019 +0200
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 6a79e59bc..bb04fdbc0 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -639,10 +639,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);
@@ -650,6 +650,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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]