From 74986cc59a259d011410493e1d4a522cb00563b2 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Fri, 11 Dec 2015 11:25:35 +0800 Subject: [PATCH] g_free() can handle NULL pointer --- qemu/memory.c | 8 ++++---- uc.c | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/qemu/memory.c b/qemu/memory.c index 3394440..a767bf0 100644 --- a/qemu/memory.c +++ b/qemu/memory.c @@ -69,10 +69,8 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr) //shift remainder of array down over deleted pointer memcpy(&uc->mapped_blocks[i], &uc->mapped_blocks[i + 1], sizeof(MemoryRegion*) * (uc->mapped_block_count - i)); mr->destructor(mr); - if((char *)mr->name) - g_free((char *)mr->name); - if(mr->ioeventfds) - g_free(mr->ioeventfds); + g_free((char *)mr->name); + g_free(mr->ioeventfds); break; } } @@ -81,12 +79,14 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr) int memory_free(struct uc_struct *uc) { 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]); } + return 0; } diff --git a/uc.c b/uc.c index 5d12298..7e2d5fa 100644 --- a/uc.c +++ b/uc.c @@ -277,10 +277,8 @@ uc_err uc_close(uc_engine *uc) for (i = 0; i < uc->mapped_block_count; i++) { mr = uc->mapped_blocks[i]; mr->destructor(mr); - if((char *)mr->name) - g_free((char *)mr->name); - if(mr->ioeventfds) - g_free(mr->ioeventfds); + g_free((char *)mr->name); + g_free(mr->ioeventfds); } free((void*) uc->system_memory->name);