Module: Mesa
Branch: main
Commit: ff494361bee7506db701cb861073ab194ae3a6e9
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ff494361bee7506db701cb861073ab194ae3a6e9

Author: Dylan Baker <[email protected]>
Date:   Thu Feb 23 09:50:33 2023 -0800

util: rzalloc and free hash_table_u64

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 <[email protected]>
Reviewed-by: Tapani Pälli <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21499>

---

 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

Reply via email to