]> Git Repo - qemu.git/commitdiff
exec: Stop using memory after free
authorDon Slutz <[email protected]>
Mon, 30 Nov 2015 22:11:04 +0000 (17:11 -0500)
committerPaolo Bonzini <[email protected]>
Wed, 2 Dec 2015 11:01:43 +0000 (12:01 +0100)
memory_region_unref(mr) can free memory.

For example I got:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f43280d4700 (LWP 4462)]
0x00007f43323283c0 in phys_section_destroy (mr=0x7f43259468b0)
    at /home/don/xen/tools/qemu-xen-dir/exec.c:1023
1023        if (mr->subpage) {
(gdb) bt
    at /home/don/xen/tools/qemu-xen-dir/exec.c:1023
    at /home/don/xen/tools/qemu-xen-dir/exec.c:1034
    at /home/don/xen/tools/qemu-xen-dir/exec.c:2205
(gdb) p mr
$1 = (MemoryRegion *) 0x7f43259468b0

And this change prevents this.

Signed-off-by: Don Slutz <[email protected]>
Message-Id: <1448921464[email protected]>
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
exec.c

diff --git a/exec.c b/exec.c
index de1cf191549fbf91cadc5703d1bfff31529c681f..0bf0a6e7eb04fe38379ea84023eb61f977c8a474 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -1064,9 +1064,11 @@ static uint16_t phys_section_add(PhysPageMap *map,
 
 static void phys_section_destroy(MemoryRegion *mr)
 {
+    bool have_sub_page = mr->subpage;
+
     memory_region_unref(mr);
 
-    if (mr->subpage) {
+    if (have_sub_page) {
         subpage_t *subpage = container_of(mr, subpage_t, iomem);
         object_unref(OBJECT(&subpage->iomem));
         g_free(subpage);
This page took 0.037842 seconds and 4 git commands to generate.