g_free() can handle NULL pointer

This commit is contained in:
Nguyen Anh Quynh 2015-12-11 11:25:35 +08:00
parent 909bf43e77
commit 74986cc59a
2 changed files with 6 additions and 8 deletions

View File

@ -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;
}

6
uc.c
View File

@ -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);