Module: Mesa Branch: staging/23.0 Commit: 11c2063e68aa440a03fd906a5f949c917532b281 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=11c2063e68aa440a03fd906a5f949c917532b281
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> (cherry picked from commit ff494361bee7506db701cb861073ab194ae3a6e9) --- .pick_status.json | 2 +- src/util/hash_table.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index fc7425f8723..3db2592bc26 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -94,7 +94,7 @@ "description": "util: rzalloc and free hash_table_u64", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "6649b840c34016b4753e69d4513a8d09da9febb2" }, 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
