diff mbox

[26/29] hw/arm/spitz.c: Fix memory leak spotted by valgrind

Message ID 1432814932-12608-27-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:
==19832== 244 (64 direct, 180 indirect) bytes in 1 blocks are definitely lost in loss record 2,220 of 2,846
==19832==    at 0x4C2845D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19832==    by 0x35479F: malloc_and_trace (vl.c:2556)
==19832==    by 0x64C770E: g_malloc (in /usr/lib64/libglib-2.0.so.0.3600.3)
==19832==    by 0x3ED99B: qemu_extend_irqs (irq.c:55)
==19832==    by 0x3EDA27: qemu_allocate_irqs (irq.c:64)
==19832==    by 0x2875CF: spitz_scoop_gpio_setup (spitz.c:818)
==19832==    by 0x2879FE: spitz_common_init (spitz.c:931)
==19832==    by 0x287AEF: spitz_init (spitz.c:957)
==19832==    by 0x358B6A: main (vl.c:4249)

Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 hw/arm/spitz.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
index 5bf032a..6ff1825 100644
--- a/hw/arm/spitz.c
+++ b/hw/arm/spitz.c
@@ -815,7 +815,7 @@  static void spitz_out_switch(void *opaque, int line, int level)
 static void spitz_scoop_gpio_setup(PXA2xxState *cpu,
                 DeviceState *scp0, DeviceState *scp1)
 {
-    qemu_irq *outsignals = qemu_allocate_irqs(spitz_out_switch, cpu, 8);
+    qemu_irq *outsignals = qemu_allocate_irqs(spitz_out_switch, cpu, 7);
 
     qdev_connect_gpio_out(scp0, SPITZ_SCP_CHRG_ON, outsignals[0]);
     qdev_connect_gpio_out(scp0, SPITZ_SCP_JK_B, outsignals[1]);
@@ -825,9 +825,13 @@  static void spitz_scoop_gpio_setup(PXA2xxState *cpu,
     if (scp1) {
         qdev_connect_gpio_out(scp1, SPITZ_SCP2_BACKLIGHT_CONT, outsignals[4]);
         qdev_connect_gpio_out(scp1, SPITZ_SCP2_BACKLIGHT_ON, outsignals[5]);
+    } else {
+        qemu_free_irq(outsignals[4]);
+        qemu_free_irq(outsignals[5]);
     }
 
     qdev_connect_gpio_out(scp0, SPITZ_SCP_ADC_TEMP_ON, outsignals[6]);
+    g_free(outsignals);
 }
 
 #define SPITZ_GPIO_HSYNC		22