[glib/wip/desrt/more-ghash-valgrind: 11/13] ghash: do less work when destroying the table
- From: Allison Karlitskaya <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/desrt/more-ghash-valgrind: 11/13] ghash: do less work when destroying the table
- Date: Mon, 20 May 2019 15:05:00 +0000 (UTC)
commit b3fbf6c18ba35bd5210d2c08f035f3516bb668aa
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 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]