diff mbox

[18/29] hw/m68k/mcf5206.c: Fix memory leak spotted by valgrind

Message ID 1432814932-12608-19-git-send-email-zhaoshenglong@huawei.com
State New
Headers show

Commit Message

Shannon Zhao May 28, 2015, 12:08 p.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>

valgrind complains about:
==16659== 1,912 (112 direct, 1,800 indirect) bytes in 1 blocks are definitely lost in loss record 1,254 of 1,285
==16659==    at 0x4C2845D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==16659==    by 0x251F97: malloc_and_trace (vl.c:2556)
==16659==    by 0x64C770E: g_malloc (in /usr/lib64/libglib-2.0.so.0.3600.3)
==16659==    by 0x2C994F: qemu_extend_irqs (irq.c:55)
==16659==    by 0x2C99DB: qemu_allocate_irqs (irq.c:64)
==16659==    by 0x225878: mcf5206_init (mcf5206.c:539)
==16659==    by 0x223991: an5206_init (an5206.c:61)
==16659==    by 0x256362: main (vl.c:4249)

Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 hw/m68k/mcf5206.c     | 10 ++++++++--
 include/hw/m68k/mcf.h |  3 +--
 2 files changed, 9 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/hw/m68k/mcf5206.c b/hw/m68k/mcf5206.c
index 1727a46..67390e6 100644
--- a/hw/m68k/mcf5206.c
+++ b/hw/m68k/mcf5206.c
@@ -525,10 +525,11 @@  static const MemoryRegionOps m5206_mbar_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-qemu_irq *mcf5206_init(MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu)
+void mcf5206_init(MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu)
 {
     m5206_mbar_state *s;
     qemu_irq *pic;
+    int i;
 
     s = (m5206_mbar_state *)g_malloc0(sizeof(m5206_mbar_state));
 
@@ -543,6 +544,11 @@  qemu_irq *mcf5206_init(MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu)
     s->uart[1] = mcf_uart_init(pic[13], serial_hds[1]);
     s->cpu = cpu;
 
+    for (i = 0; i < 9; i++) {
+        qemu_free_irq(pic[i]);
+    }
+    qemu_free_irq(pic[11]);
+    g_free(pic);
+
     m5206_mbar_reset(s);
-    return pic;
 }
diff --git a/include/hw/m68k/mcf.h b/include/hw/m68k/mcf.h
index fbc8dc2..9bf4f5f 100644
--- a/include/hw/m68k/mcf.h
+++ b/include/hw/m68k/mcf.h
@@ -24,7 +24,6 @@  void mcf_fec_init(struct MemoryRegion *sysmem, NICInfo *nd,
                   hwaddr base, qemu_irq *irq);
 
 /* mcf5206.c */
-qemu_irq *mcf5206_init(struct MemoryRegion *sysmem,
-                       uint32_t base, M68kCPU *cpu);
+void mcf5206_init(struct MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu);
 
 #endif