Fix memory leak of custom helpers

This commit is contained in:
lazymio 2022-01-20 19:50:57 +01:00
parent bbfb376a88
commit 55b4865945
No known key found for this signature in database
GPG Key ID: DFF27E34A47CB873
3 changed files with 6 additions and 0 deletions

View File

@ -692,6 +692,7 @@ struct TCGContext {
TCGOp *icount_start_insn;
/* qemu/tcg/tcg.c */
GHashTable *helper_table;
GHashTable *custom_helper_infos; // To support inline hooks.
TCGv_ptr cpu_env;
struct tcg_region_state region;
GTree *tree;

View File

@ -692,6 +692,7 @@ void uc_add_inline_hook(uc_engine *uc, struct hook *hk, void** args, int args_le
info->sizemask = sizemask;
g_hash_table_insert(helper_table, (gpointer)info->func, (gpointer)info);
g_hash_table_insert(uc->tcg_ctx->custom_helper_infos, (gpointer)info->func, (gpointer)info);
tcg_gen_callN(tcg_ctx, info->func, NULL, args_len, (TCGTemp**)args);
}
@ -752,6 +753,9 @@ void tcg_context_init(TCGContext *s)
helper_table = g_hash_table_new(NULL, NULL);
s->helper_table = helper_table;
// Unicorn: Store our custom inline hooks infomation
s->custom_helper_infos = g_hash_table_new_full(NULL, NULL, NULL, g_free);
for (i = 0; i < ARRAY_SIZE(all_helpers); ++i) {
g_hash_table_insert(helper_table, (gpointer)all_helpers[i].func,
(gpointer)&all_helpers[i]);

View File

@ -49,6 +49,7 @@ static void release_common(void *t)
}
tcg_pool_reset(s);
g_hash_table_destroy(s->helper_table);
g_hash_table_destroy(s->custom_helper_infos);
g_free(s->indirect_reg_alloc_order);
/* qemu/tcg/tcg/c:4018: img = g_malloc(img_size); */
g_free((void *)(s->one_entry->symfile_addr));