From ff494361bee7506db701cb861073ab194ae3a6e9 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 23 Feb 2023 09:50:33 -0800 Subject: [PATCH] util: rzalloc and free hash_table_u64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we're prone to leaking the table itself, since it's not freed in the destroy function CID: 1516552 fixes: 6649b840c34016b4753e69d4513a8d09da9febb2 ("mesa/util: add a hash table wrapper which support 64-bit keys") Reviewed-by: Faith Ekstrand Reviewed-by: Tapani Pälli Part-of: --- src/util/hash_table.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/util/hash_table.c b/src/util/hash_table.c index b0e7506ab8e..dc00b2de8e9 100644 --- a/src/util/hash_table.c +++ b/src/util/hash_table.c @@ -775,15 +775,15 @@ _mesa_hash_table_u64_create(void *mem_ctx) STATIC_ASSERT(FREED_KEY_VALUE != DELETED_KEY_VALUE); struct hash_table_u64 *ht; - ht = CALLOC_STRUCT(hash_table_u64); + ht = rzalloc(mem_ctx, struct hash_table_u64); if (!ht) return NULL; if (sizeof(void *) == 8) { - ht->table = _mesa_hash_table_create(mem_ctx, _mesa_hash_pointer, + ht->table = _mesa_hash_table_create(ht, _mesa_hash_pointer, _mesa_key_pointer_equal); } else { - ht->table = _mesa_hash_table_create(mem_ctx, key_u64_hash, + ht->table = _mesa_hash_table_create(ht, key_u64_hash, key_u64_equals); } @@ -821,10 +821,7 @@ _mesa_hash_table_u64_destroy(struct hash_table_u64 *ht) { if (!ht) return; - - _mesa_hash_table_u64_clear(ht); - _mesa_hash_table_destroy(ht->table, NULL); - free(ht); + ralloc_free(ht); } void