util/hash_table: do not leak u64 struct key

For non 64bit devices the key stored in hash_table_u64 is wrapped in
hash_key_u64 structure, which is never free.

This commit fixes this issue by just removing the user-defined
`delete_function` parameter in hash_table_u64_{destroy,clear} (which
nobody is using) and using instead a delete function to free this
structure.

Fixes: 608257cf82 ("i965: Fix INTEL_DEBUG=bat")
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10480>
This commit is contained in:
Juan A. Suarez Romero 2021-04-27 12:08:50 +02:00
parent 33f9b06b0e
commit e532a47f76
13 changed files with 36 additions and 68 deletions

View File

@ -2770,7 +2770,7 @@ emit_block(struct ir3_context *ctx, nir_block *nblock)
ctx->addr0_ht[i] = NULL;
}
_mesa_hash_table_u64_destroy(ctx->addr1_ht, NULL);
_mesa_hash_table_u64_destroy(ctx->addr1_ht);
ctx->addr1_ht = NULL;
nir_foreach_instr (instr, nblock) {

View File

@ -972,12 +972,12 @@ bool ppir_compile_nir(struct lima_fs_compiled_shader *prog, struct nir_shader *n
ppir_print_shader_db(nir, comp, debug);
_mesa_hash_table_u64_destroy(comp->blocks, NULL);
_mesa_hash_table_u64_destroy(comp->blocks);
ralloc_free(comp);
return true;
err_out0:
_mesa_hash_table_u64_destroy(comp->blocks, NULL);
_mesa_hash_table_u64_destroy(comp->blocks);
ralloc_free(comp);
return false;
}

View File

@ -636,7 +636,7 @@ static void radeon_winsys_destroy(struct radeon_winsys *rws)
_mesa_hash_table_destroy(ws->bo_names, NULL);
_mesa_hash_table_destroy(ws->bo_handles, NULL);
_mesa_hash_table_u64_destroy(ws->bo_vas, NULL);
_mesa_hash_table_u64_destroy(ws->bo_vas);
mtx_destroy(&ws->bo_handles_mutex);
mtx_destroy(&ws->vm32.mutex);
mtx_destroy(&ws->vm64.mutex);

View File

@ -285,7 +285,7 @@ brw_batch_reset(struct brw_context *brw)
batch->state_base_address_emitted = false;
if (batch->state_batch_sizes)
_mesa_hash_table_u64_clear(batch->state_batch_sizes, NULL);
_mesa_hash_table_u64_clear(batch->state_batch_sizes);
/* Always add workaround_bo which contains a driver identifier to be
* recorded in error states.
@ -357,7 +357,7 @@ brw_batch_free(struct brw_batch *batch)
brw_bo_unreference(batch->batch.bo);
brw_bo_unreference(batch->state.bo);
if (batch->state_batch_sizes) {
_mesa_hash_table_u64_destroy(batch->state_batch_sizes, NULL);
_mesa_hash_table_u64_destroy(batch->state_batch_sizes);
intel_batch_decode_ctx_finish(&batch->decoder);
}
}

View File

@ -1951,7 +1951,7 @@ _mesa_create_program_resource_hash(struct gl_shader_program *shProg)
{
/* Rebuild resource hash. */
if (shProg->data->ProgramResourceHash)
_mesa_hash_table_u64_destroy(shProg->data->ProgramResourceHash, NULL);
_mesa_hash_table_u64_destroy(shProg->data->ProgramResourceHash);
shProg->data->ProgramResourceHash = _mesa_hash_table_u64_create(shProg);

View File

@ -358,7 +358,7 @@ _mesa_clear_shader_program_data(struct gl_context *ctx,
}
if (shProg->data && shProg->data->ProgramResourceHash) {
_mesa_hash_table_u64_destroy(shProg->data->ProgramResourceHash, NULL);
_mesa_hash_table_u64_destroy(shProg->data->ProgramResourceHash);
shProg->data->ProgramResourceHash = NULL;
}

View File

@ -378,8 +378,8 @@ _mesa_init_resident_handles(struct gl_context *ctx)
void
_mesa_free_resident_handles(struct gl_context *ctx)
{
_mesa_hash_table_u64_destroy(ctx->ResidentTextureHandles, NULL);
_mesa_hash_table_u64_destroy(ctx->ResidentImageHandles, NULL);
_mesa_hash_table_u64_destroy(ctx->ResidentTextureHandles);
_mesa_hash_table_u64_destroy(ctx->ResidentImageHandles);
}
/**
@ -397,10 +397,10 @@ void
_mesa_free_shared_handles(struct gl_shared_state *shared)
{
if (shared->TextureHandles)
_mesa_hash_table_u64_destroy(shared->TextureHandles, NULL);
_mesa_hash_table_u64_destroy(shared->TextureHandles);
if (shared->ImageHandles)
_mesa_hash_table_u64_destroy(shared->ImageHandles, NULL);
_mesa_hash_table_u64_destroy(shared->ImageHandles);
mtx_destroy(&shared->HandlesMutex);
}

View File

@ -1462,6 +1462,6 @@ dxil_nir_create_bare_samplers(nir_shader *nir)
bool progress = nir_shader_instructions_pass(nir, redirect_sampler_derefs,
nir_metadata_block_index | nir_metadata_dominance | nir_metadata_loop_analysis, sampler_to_bare);
_mesa_hash_table_u64_destroy(sampler_to_bare, NULL);
_mesa_hash_table_u64_destroy(sampler_to_bare);
return progress;
}

View File

@ -214,7 +214,7 @@ pandecode_next_frame(void)
void
pandecode_close(void)
{
_mesa_hash_table_u64_destroy(mmap_table, NULL);
_mesa_hash_table_u64_destroy(mmap_table);
util_dynarray_fini(&ro_mappings);
pandecode_dump_file_close();
}

View File

@ -83,5 +83,5 @@ mir_squeeze_index(compiler_context *ctx)
ctx->blend_input = find_or_allocate_temp(ctx, map, ctx->blend_input);
ctx->blend_src1 = find_or_allocate_temp(ctx, map, ctx->blend_src1);
_mesa_hash_table_u64_destroy(map, NULL);
_mesa_hash_table_u64_destroy(map);
}

View File

@ -304,7 +304,7 @@ foz_destroy(struct foz_db *foz_db)
}
if (foz_db->mem_ctx) {
_mesa_hash_table_u64_destroy(foz_db->index_db, NULL);
_mesa_hash_table_u64_destroy(foz_db->index_db);
ralloc_free(foz_db->mem_ctx);
simple_mtx_destroy(&foz_db->mtx);
}

View File

@ -768,65 +768,35 @@ _mesa_hash_table_u64_create(void *mem_ctx)
return ht;
}
void
_mesa_hash_table_u64_clear(struct hash_table_u64 *ht,
void (*delete_function)(struct hash_entry *entry))
static void
_mesa_hash_table_u64_delete_key(struct hash_entry *entry)
{
if (!ht)
if (sizeof(void *) == 8)
return;
if (ht->deleted_key_data) {
if (delete_function) {
struct hash_table *table = ht->table;
struct hash_entry entry;
struct hash_key_u64 *_key = (struct hash_key_u64 *)entry->key;
/* Create a fake entry for the delete function. */
if (sizeof(void *) == 8) {
entry.hash = table->key_hash_function(table->deleted_key);
} else {
struct hash_key_u64 _key = { .value = (uintptr_t)table->deleted_key };
entry.hash = table->key_hash_function(&_key);
}
entry.key = table->deleted_key;
entry.data = ht->deleted_key_data;
delete_function(&entry);
}
ht->deleted_key_data = NULL;
}
if (ht->freed_key_data) {
if (delete_function) {
struct hash_table *table = ht->table;
struct hash_entry entry;
/* Create a fake entry for the delete function. */
if (sizeof(void *) == 8) {
entry.hash = table->key_hash_function(uint_key(FREED_KEY_VALUE));
} else {
struct hash_key_u64 _key = { .value = (uintptr_t)FREED_KEY_VALUE };
entry.hash = table->key_hash_function(&_key);
}
entry.key = uint_key(FREED_KEY_VALUE);
entry.data = ht->freed_key_data;
delete_function(&entry);
}
ht->freed_key_data = NULL;
}
_mesa_hash_table_clear(ht->table, delete_function);
if (_key)
free(_key);
}
void
_mesa_hash_table_u64_destroy(struct hash_table_u64 *ht,
void (*delete_function)(struct hash_entry *entry))
_mesa_hash_table_u64_clear(struct hash_table_u64 *ht)
{
if (!ht)
return;
_mesa_hash_table_u64_clear(ht, delete_function);
_mesa_hash_table_destroy(ht->table, delete_function);
_mesa_hash_table_clear(ht->table, _mesa_hash_table_u64_delete_key);
}
void
_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);
}

View File

@ -172,8 +172,7 @@ struct hash_table_u64 *
_mesa_hash_table_u64_create(void *mem_ctx);
void
_mesa_hash_table_u64_destroy(struct hash_table_u64 *ht,
void (*delete_function)(struct hash_entry *entry));
_mesa_hash_table_u64_destroy(struct hash_table_u64 *ht);
void
_mesa_hash_table_u64_insert(struct hash_table_u64 *ht, uint64_t key,
@ -186,8 +185,7 @@ void
_mesa_hash_table_u64_remove(struct hash_table_u64 *ht, uint64_t key);
void
_mesa_hash_table_u64_clear(struct hash_table_u64 *ht,
void (*delete_function)(struct hash_entry *entry));
_mesa_hash_table_u64_clear(struct hash_table_u64 *ht);
#ifdef __cplusplus
} /* extern C */