[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 21/22] target/arm: Create timers in realize, not init
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PULL 21/22] target/arm: Create timers in realize, not init |
Date: |
Fri, 14 Dec 2018 14:42:13 +0000 |
The timer_new() function allocates memory; this means that
if we call it in the CPU's init method we would need
to provide an instance_finalize method to free it. Defer
the timer creation to the realize function instead.
This fixes a memory leak spotted by clang LeakSanitizer
when a CPU object is created for introspection.
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Message-id: address@hidden
---
target/arm/cpu.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index b84a6c0e678..0e7138c9bfb 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -679,14 +679,6 @@ static void arm_cpu_initfn(Object *obj)
qdev_init_gpio_in(DEVICE(cpu), arm_cpu_set_irq, 4);
}
- cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
- arm_gt_ptimer_cb, cpu);
- cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
- arm_gt_vtimer_cb, cpu);
- cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
- arm_gt_htimer_cb, cpu);
- cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
- arm_gt_stimer_cb, cpu);
qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs,
ARRAY_SIZE(cpu->gt_timer_outputs));
@@ -882,6 +874,15 @@ static void arm_cpu_realizefn(DeviceState *dev, Error
**errp)
return;
}
}
+
+ cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
+ arm_gt_ptimer_cb, cpu);
+ cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
+ arm_gt_vtimer_cb, cpu);
+ cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
+ arm_gt_htimer_cb, cpu);
+ cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
+ arm_gt_stimer_cb, cpu);
#endif
cpu_exec_realizefn(cs, &local_err);
--
2.19.2
- [Qemu-devel] [PULL 08/22] hw/ppc/ppc405_boards: Don't use load_image(), (continued)
- [Qemu-devel] [PULL 08/22] hw/ppc/ppc405_boards: Don't use load_image(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 11/22] hw/i386/pc.c: Don't use load_image(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 10/22] hw/pci/pci.c: Don't use load_image(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 12/22] hw/i386/multiboot.c: Don't use load_image(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 13/22] hw/block/tc58128.c: Don't use load_image(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 14/22] device_tree.c: Don't use load_image(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 15/22] hw/core/loader.c: Remove load_image(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 19/22] hw/sd/sdhci: Don't leak memory region in sdhci_sysbus_realize(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 17/22] target/arm: Free name string in ARMCPRegInfo hashtable entries, Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 16/22] include/hw/loader.h: Document load_image_size(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 21/22] target/arm: Create timers in realize, not init,
Peter Maydell <=
- [Qemu-devel] [PULL 22/22] virt: Fix broken indentation, Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 18/22] hw/arm/mps2-tz.c: Free mscname string in make_dma(), Peter Maydell, 2018/12/14
- [Qemu-devel] [PULL 20/22] tests/test-arm-mptimer: Don't leak string memory, Peter Maydell, 2018/12/14
- Re: [Qemu-devel] [PULL 00/22] misc queue, Peter Maydell, 2018/12/16
- Re: [Qemu-devel] [PULL 00/22] misc queue, Peter Maydell, 2018/12/16
- Re: [Qemu-devel] [PULL 00/22] misc queue, no-reply, 2018/12/23