diff mbox

[21/29] hw/sh4/r2d.c: Fix memory leak spotted by valgrind

Message ID 1432814932-12608-22-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:
==29844== 1,364 (104 direct, 1,260 indirect) bytes in 1 blocks are definitely lost in loss record 2,143 of 2,205
==29844==    at 0x4C2845D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==29844==    by 0x25096F: malloc_and_trace (vl.c:2556)
==29844==    by 0x64C770E: g_malloc (in /usr/lib64/libglib-2.0.so.0.3600.3)
==29844==    by 0x2C7CDB: qemu_extend_irqs (irq.c:55)
==29844==    by 0x2C7D67: qemu_allocate_irqs (irq.c:64)
==29844==    by 0x2167ED: r2d_fpga_init (r2d.c:191)
==29844==    by 0x2169CC: r2d_init (r2d.c:263)
==29844==    by 0x254D3A: main (vl.c:4249)

Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 hw/sh4/r2d.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Peter Maydell May 28, 2015, 12:46 p.m. UTC | #1
On 28 May 2015 at 13:08, Shannon Zhao <zhaoshenglong@huawei.com> wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
>
> valgrind complains about:
> ==29844== 1,364 (104 direct, 1,260 indirect) bytes in 1 blocks are definitely lost in loss record 2,143 of 2,205
> ==29844==    at 0x4C2845D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==29844==    by 0x25096F: malloc_and_trace (vl.c:2556)
> ==29844==    by 0x64C770E: g_malloc (in /usr/lib64/libglib-2.0.so.0.3600.3)
> ==29844==    by 0x2C7CDB: qemu_extend_irqs (irq.c:55)
> ==29844==    by 0x2C7D67: qemu_allocate_irqs (irq.c:64)
> ==29844==    by 0x2167ED: r2d_fpga_init (r2d.c:191)
> ==29844==    by 0x2169CC: r2d_init (r2d.c:263)
> ==29844==    by 0x254D3A: main (vl.c:4249)
>
> Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> ---
>  hw/sh4/r2d.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
> index 4221060..594c733 100644
> --- a/hw/sh4/r2d.c
> +++ b/hw/sh4/r2d.c
> @@ -287,6 +287,16 @@ static void r2d_init(MachineState *machine)
>      sysbus_mmio_map(busdev, 1, 0x1400080c);
>      mmio_ide_init_drives(dev, dinfo, NULL);
>
> +    /* free unused irq */
> +    qemu_free_irq(irq[CF_CD]);
> +    qemu_free_irq(irq[KEY]);
> +    qemu_free_irq(irq[RTC_A]);
> +    qemu_free_irq(irq[RTC_T]);
> +    qemu_free_irq(irq[SDCARD]);
> +    qemu_free_irq(irq[EXT]);
> +    qemu_free_irq(irq[TP]);
> +    g_free(irq);
> +

Yuck. We should just save the irq pointer in some state structure
and g_free_irqs() it all in deinit.

-- PMM
diff mbox

Patch

diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index 4221060..594c733 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -287,6 +287,16 @@  static void r2d_init(MachineState *machine)
     sysbus_mmio_map(busdev, 1, 0x1400080c);
     mmio_ide_init_drives(dev, dinfo, NULL);
 
+    /* free unused irq */
+    qemu_free_irq(irq[CF_CD]);
+    qemu_free_irq(irq[KEY]);
+    qemu_free_irq(irq[RTC_A]);
+    qemu_free_irq(irq[RTC_T]);
+    qemu_free_irq(irq[SDCARD]);
+    qemu_free_irq(irq[EXT]);
+    qemu_free_irq(irq[TP]);
+    g_free(irq);
+
     /* onboard flash memory */
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,