aboutsummaryrefslogtreecommitdiff
path: root/hw/timer/stm32f2xx_timer.c
diff options
context:
space:
mode:
authorPan Nengyuan <pannengyuan@huawei.com>2020-02-07 14:04:28 +0000
committerPeter Maydell <peter.maydell@linaro.org>2020-02-07 14:04:28 +0000
commit53b95da1607072bc4727cbdb48a83e4befe282b4 (patch)
treeb0d342fcb8d6b90bc3bd0ea7199c281484ddbbbf /hw/timer/stm32f2xx_timer.c
parentf3a508eb4e5b486f0d6e8a16dbd8ff4b9dafcd72 (diff)
downloadqemu-53b95da1607072bc4727cbdb48a83e4befe282b4.zip
qemu-53b95da1607072bc4727cbdb48a83e4befe282b4.tar.gz
qemu-53b95da1607072bc4727cbdb48a83e4befe282b4.tar.bz2
stm32f2xx_timer: delay timer_new to avoid memleaks
There is a memory leak when we call 'device_list_properties' with typename = stm32f2xx_timer. It's easy to reproduce as follow: virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "stm32f2xx_timer"}}' This patch delay timer_new to fix this memleaks. Reported-by: Euler Robot <euler.robot@huawei.com> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-id: 20200205070659.22488-3-pannengyuan@huawei.com Cc: Alistair Francis <alistair@alistair23.me> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/timer/stm32f2xx_timer.c')
-rw-r--r--hw/timer/stm32f2xx_timer.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
index fb370ce..06ec8a0 100644
--- a/hw/timer/stm32f2xx_timer.c
+++ b/hw/timer/stm32f2xx_timer.c
@@ -314,7 +314,11 @@ static void stm32f2xx_timer_init(Object *obj)
memory_region_init_io(&s->iomem, obj, &stm32f2xx_timer_ops, s,
"stm32f2xx_timer", 0x400);
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
+static void stm32f2xx_timer_realize(DeviceState *dev, Error **errp)
+{
+ STM32F2XXTimerState *s = STM32F2XXTIMER(dev);
s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, stm32f2xx_timer_interrupt, s);
}
@@ -325,6 +329,7 @@ static void stm32f2xx_timer_class_init(ObjectClass *klass, void *data)
dc->reset = stm32f2xx_timer_reset;
device_class_set_props(dc, stm32f2xx_timer_properties);
dc->vmsd = &vmstate_stm32f2xx_timer;
+ dc->realize = stm32f2xx_timer_realize;
}
static const TypeInfo stm32f2xx_timer_info = {