Fix uc_mem_unmap memory leak and in uc_close.

It appears the problem is that we are not calling the memory region
destructor. After modifying memory_unmap to include the destructor call
for the memory region, the memory is freed.

Furthermore in uc_close we must explicitly free any blocks that were not
unmapped by the user to prevent leaks.

This should fix issue 305.
This commit is contained in:
farmdve
2015-12-11 02:42:31 +02:00
parent 9d7f81d195
commit 3e57615c76
2 changed files with 17 additions and 1 deletions

View File

@ -68,6 +68,11 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr)
uc->mapped_block_count--;
//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);
break;
}
}