Fix memory leaks as reported by DrMemory and Valgrind.

ARM and probably the rest of the arches have significant memory leaks as
they have no release interface.

Additionally, DrMemory does not have 64-bit support and thus I can't
test the 64-bit version under Windows. Under Linux valgrind supports
both 32-bit and 64-bit but there are different macros and code for Linux
and Windows.
This commit is contained in:
farmdve
2016-01-08 01:41:45 +02:00
parent 13726b3d40
commit 036763d6ae
22 changed files with 85 additions and 45 deletions

View File

@@ -70,6 +70,7 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr)
{
int i;
target_ulong addr;
Object *obj;
// Make sure all pages associated with the MemoryRegion are flushed
// Only need to do this if we are in a running state
@@ -87,8 +88,12 @@ 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);
g_free((char *)mr->name);
obj = OBJECT(mr);
obj->ref = 1;
obj->free = g_free;
g_free(mr->ioeventfds);
g_free((char *)mr->name);
mr->name = NULL;
break;
}
}
@@ -97,6 +102,7 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr)
int memory_free(struct uc_struct *uc)
{
MemoryRegion *mr;
Object *obj;
int i;
get_system_memory(uc)->enabled = false;
@@ -105,9 +111,10 @@ int memory_free(struct uc_struct *uc)
mr->enabled = false;
memory_region_del_subregion(get_system_memory(uc), mr);
mr->destructor(mr);
g_free((char *)mr->name);
obj = OBJECT(mr);
obj->ref = 1;
obj->free = g_free;
g_free(mr->ioeventfds);
g_free(mr);
}
return 0;
@@ -948,6 +955,7 @@ void memory_region_init(struct uc_struct *uc, MemoryRegion *mr,
{
if (!owner) {
owner = qdev_get_machine(uc);
uc->owner = owner;
}
object_initialize(uc, mr, sizeof(*mr), TYPE_MEMORY_REGION);