From 8b79a872d0457c7a790af1374a53679edd14c8a7 Mon Sep 17 00:00:00 2001 From: farmdve Date: Fri, 11 Dec 2015 22:35:25 +0200 Subject: [PATCH] Fix segfault introduced in my previous commits. --- qemu/memory.c | 11 ++++++++--- uc.c | 8 -------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/qemu/memory.c b/qemu/memory.c index a767bf03..5e26d83d 100644 --- a/qemu/memory.c +++ b/qemu/memory.c @@ -78,13 +78,18 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr) int memory_free(struct uc_struct *uc) { + MemoryRegion *mr; int i; get_system_memory(uc)->enabled = false; for (i = 0; i < uc->mapped_block_count; i++) { - uc->mapped_blocks[i]->enabled = false; - memory_region_del_subregion(get_system_memory(uc), uc->mapped_blocks[i]); - g_free(uc->mapped_blocks[i]); + mr = uc->mapped_blocks[i]; + mr->enabled = false; + memory_region_del_subregion(get_system_memory(uc), mr); + mr->destructor(mr); + g_free((char *)mr->name); + g_free(mr->ioeventfds); + g_free(mr); } return 0; diff --git a/uc.c b/uc.c index 2c8f9f1d..53bb682d 100644 --- a/uc.c +++ b/uc.c @@ -258,7 +258,6 @@ uc_err uc_open(uc_arch arch, uc_mode mode, uc_engine **result) UNICORN_EXPORT uc_err uc_close(uc_engine *uc) { - MemoryRegion *mr; int i; if (uc->release) @@ -274,13 +273,6 @@ uc_err uc_close(uc_engine *uc) g_free(uc->tcg_ctx); - for (i = 0; i < uc->mapped_block_count; i++) { - mr = uc->mapped_blocks[i]; - mr->destructor(mr); - g_free((char *)mr->name); - g_free(mr->ioeventfds); - } - free((void*) uc->system_memory->name); g_free(uc->system_memory); g_hash_table_destroy(uc->type_table);