From 4b529bc56cc823f1f2d0cced3398c76ed399e903 Mon Sep 17 00:00:00 2001 From: Chris Eagle Date: Wed, 26 Aug 2015 14:09:46 -0700 Subject: [PATCH] Free up all MemoryRegion* when uc is closed --- qemu/memory.c | 9 +++++---- regress/Makefile | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/qemu/memory.c b/qemu/memory.c index 74ea2cf8..8c5fd883 100755 --- a/qemu/memory.c +++ b/qemu/memory.c @@ -47,11 +47,12 @@ MemoryRegion *memory_map(struct uc_struct *uc, ram_addr_t begin, size_t size, ui int memory_free(struct uc_struct *uc) { + int i; get_system_memory(uc)->enabled = false; - if (uc->ram) { - uc->ram->enabled = false; - memory_region_del_subregion(get_system_memory(uc), uc->ram); - g_free(uc->ram); + for (i = 0; i < uc->mapped_block_count; i++) { + uc->mapped_blocks[i].region->enabled = false; + memory_region_del_subregion(get_system_memory(uc), uc->mapped_blocks[i].region); + g_free(uc->mapped_blocks[i].region); } return 0; } diff --git a/regress/Makefile b/regress/Makefile index 06c5a31a..fccfa32c 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -1,7 +1,7 @@ CFLAGS += -I../include LDFLAGS = -L.. -lunicorn -TESTS = map_crash sigill sigill2 block_test +TESTS = map_crash sigill sigill2 block_test ro_mem_test all: $(TESTS)