On 2015/5/28 20:46, Peter Maydell wrote: > On 28 May 2015 at 13:08, Shannon Zhao <zhaoshengl...@huawei.com> wrote: >> > From: Shannon Zhao <shannon.z...@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 <zhaoshengl...@huawei.com> >> > Signed-off-by: Shannon Zhao <shannon.z...@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.
Ok, will try to use this way for those which allocate a few irqs. But the modifications for the ones which only allocate one irq are ok I guess, I use qemu_allocate_irq to replace qemu_allocate_irqs. -- Shannon