Commit e532a47f authored by Juan A. Suárez's avatar Juan A. Suárez
Browse files

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: 608257cf

 ("i965: Fix INTEL_DEBUG=bat")
Reviewed-by: default avatarIan Romanick <ian.d.romanick@intel.com>
Signed-off-by: Juan A. Suárez's avatarJuan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <!10480>
parent 33f9b06b
Pipeline #310675 waiting for manual action with stages
......@@ -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) {
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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);
}
}
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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;
}
......@@ -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();
}
......@@ -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);
}
......@@ -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);
}
......
......@@ -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;
/* 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;
struct hash_key_u64 *_key = (struct hash_key_u64 *)entry->key;
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;
if (_key)
free(_key);
}
delete_function(&entry);
}
ht->freed_key_data = NULL;
}
void
_mesa_hash_table_u64_clear(struct hash_table_u64 *ht)
{
if (!ht)
return;
_mesa_hash_table_clear(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,
void (*delete_function)(struct hash_entry *entry))
_mesa_hash_table_u64_destroy(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_u64_clear(ht);
_mesa_hash_table_destroy(ht->table, NULL);
free(ht);
}
......
......@@ -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 */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment