From 96ce92025dfc69e1c511581d4c94608d39fd8fe3 Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Wed, 15 May 2019 16:17:04 +0200 Subject: [PATCH] ghash: fix bug introduced by valgrind fix g_hash_table_new_full() had an invocation of g_hash_table_realloc_key_or_value_array() with the @is_big argument incorrectly hardcoded to FALSE, even though later in the function the values of have_big_keys and have_big_values would be set conditionally. This never caused problems before because on 64bit platforms, this would result in the allocation of a guint-sized array (which would be fine, as have_big_keys and have_big_values would always start out as false) and on 32bit platforms, this function ignored the value and always allocated a gpointer-sized array. Since merge request GNOME/glib!845 we have the possibility for have_big_keys and have_big_values to start out as TRUE on 64bit platforms. We need to make sure we pass the argument through correctly. --- glib/ghash.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/glib/ghash.c b/glib/ghash.c index 4204f51a4..14cbaf80b 100644 --- a/glib/ghash.c +++ b/glib/ghash.c @@ -1019,22 +1019,6 @@ g_hash_table_new_full (GHashFunc hash_func, GHashTable *hash_table; gboolean small; - hash_table = g_slice_new (GHashTable); - g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT); - g_atomic_ref_count_init (&hash_table->ref_count); - hash_table->nnodes = 0; - hash_table->noccupied = 0; - hash_table->hash_func = hash_func ? hash_func : g_direct_hash; - hash_table->key_equal_func = key_equal_func; -#ifndef G_DISABLE_ASSERT - hash_table->version = 0; -#endif - hash_table->key_destroy_func = key_destroy_func; - hash_table->value_destroy_func = value_destroy_func; - 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); - /* We want to use small arrays only if: * - we are running on a system where that makes sense (64 bit); and * - we are not running under valgrind. @@ -1050,8 +1034,23 @@ g_hash_table_new_full (GHashFunc hash_func, # endif #endif - hash_table->have_big_keys = !small; - hash_table->have_big_values = !small; + hash_table = g_slice_new (GHashTable); + g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT); + g_atomic_ref_count_init (&hash_table->ref_count); + hash_table->nnodes = 0; + hash_table->noccupied = 0; + hash_table->hash_func = hash_func ? hash_func : g_direct_hash; + hash_table->key_equal_func = key_equal_func; +#ifndef G_DISABLE_ASSERT + hash_table->version = 0; +#endif + hash_table->key_destroy_func = key_destroy_func; + hash_table->value_destroy_func = value_destroy_func; + hash_table->have_big_keys = !small; + hash_table->have_big_values = !small; + hash_table->keys = g_hash_table_realloc_key_or_value_array (NULL, hash_table->size, hash_table->have_big_keys); + hash_table->values = hash_table->keys; + hash_table->hashes = g_new0 (guint, hash_table->size); return hash_table; }