[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 20/30] lm32: do not leak memory on object_new/object_unref
From: |
Paolo Bonzini |
Subject: |
[PULL 20/30] lm32: do not leak memory on object_new/object_unref |
Date: |
Wed, 2 Oct 2019 18:51:43 +0200 |
Bottom halves and ptimers are malloced, but nothing in these
files is freeing memory allocated by instance_init. Since
these are sysctl devices that are never unrealized, just moving
the allocations to realize is enough to avoid the leak in
practice (and also to avoid upsetting asan when running
device-introspect-test).
Signed-off-by: Paolo Bonzini <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/timer/lm32_timer.c | 6 +++---
hw/timer/milkymist-sysctl.c | 10 +++++-----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/hw/timer/lm32_timer.c b/hw/timer/lm32_timer.c
index ac3edaf..cf316ed 100644
--- a/hw/timer/lm32_timer.c
+++ b/hw/timer/lm32_timer.c
@@ -186,9 +186,6 @@ static void lm32_timer_init(Object *obj)
sysbus_init_irq(dev, &s->irq);
- s->bh = qemu_bh_new(timer_hit, s);
- s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
-
memory_region_init_io(&s->iomem, obj, &timer_ops, s,
"timer", R_MAX * 4);
sysbus_init_mmio(dev, &s->iomem);
@@ -198,6 +195,9 @@ static void lm32_timer_realize(DeviceState *dev, Error
**errp)
{
LM32TimerState *s = LM32_TIMER(dev);
+ s->bh = qemu_bh_new(timer_hit, s);
+ s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
+
ptimer_set_freq(s->ptimer, s->freq_hz);
}
diff --git a/hw/timer/milkymist-sysctl.c b/hw/timer/milkymist-sysctl.c
index 9583507..6aedc11 100644
--- a/hw/timer/milkymist-sysctl.c
+++ b/hw/timer/milkymist-sysctl.c
@@ -283,11 +283,6 @@ static void milkymist_sysctl_init(Object *obj)
sysbus_init_irq(dev, &s->timer0_irq);
sysbus_init_irq(dev, &s->timer1_irq);
- s->bh0 = qemu_bh_new(timer0_hit, s);
- s->bh1 = qemu_bh_new(timer1_hit, s);
- s->ptimer0 = ptimer_init(s->bh0, PTIMER_POLICY_DEFAULT);
- s->ptimer1 = ptimer_init(s->bh1, PTIMER_POLICY_DEFAULT);
-
memory_region_init_io(&s->regs_region, obj, &sysctl_mmio_ops, s,
"milkymist-sysctl", R_MAX * 4);
sysbus_init_mmio(dev, &s->regs_region);
@@ -297,6 +292,11 @@ static void milkymist_sysctl_realize(DeviceState *dev,
Error **errp)
{
MilkymistSysctlState *s = MILKYMIST_SYSCTL(dev);
+ s->bh0 = qemu_bh_new(timer0_hit, s);
+ s->bh1 = qemu_bh_new(timer1_hit, s);
+ s->ptimer0 = ptimer_init(s->bh0, PTIMER_POLICY_DEFAULT);
+ s->ptimer1 = ptimer_init(s->bh1, PTIMER_POLICY_DEFAULT);
+
ptimer_set_freq(s->ptimer0, s->freq_hz);
ptimer_set_freq(s->ptimer1, s->freq_hz);
}
--
1.8.3.1
- Re: [PULL 12/30] Makefile: Remove generated files when doing 'distclean', (continued)
[PULL 13/30] hw/isa: Introduce a CONFIG_ISA_SUPERIO switch for isa-superio.c, Paolo Bonzini, 2019/10/02
[PULL 14/30] ide: fix leak from qemu_allocate_irqs, Paolo Bonzini, 2019/10/02
[PULL 16/30] mcf5208: fix leak from qemu_allocate_irqs, Paolo Bonzini, 2019/10/02
[PULL 15/30] microblaze: fix leak of fdevice tree blob, Paolo Bonzini, 2019/10/02
[PULL 17/30] hppa: fix leak from g_strdup_printf, Paolo Bonzini, 2019/10/02
[PULL 18/30] mips: fix memory leaks in board initialization, Paolo Bonzini, 2019/10/02
[PULL 20/30] lm32: do not leak memory on object_new/object_unref,
Paolo Bonzini <=
[PULL 21/30] docker: test-debug: disable LeakSanitizer, Paolo Bonzini, 2019/10/02
[PULL 19/30] cris: do not leak struct cris_disasm_data, Paolo Bonzini, 2019/10/02
[PULL 22/30] i386: Add CPUID bit for CLZERO and XSAVEERPTR, Paolo Bonzini, 2019/10/02
[PULL 23/30] vfio: Turn the container error into an Error handle, Paolo Bonzini, 2019/10/02
[PULL 25/30] Fix wrong behavior of cpu_memory_rw_debug() function in SMM, Paolo Bonzini, 2019/10/02
[PULL 26/30] util: WSAEWOULDBLOCK on connect should map to EINPROGRESS, Paolo Bonzini, 2019/10/02
[PULL 24/30] memory: allow memory_region_register_iommu_notifier() to fail, Paolo Bonzini, 2019/10/02
[PULL 28/30] win32: work around main-loop busy loop on socket/fd event, Paolo Bonzini, 2019/10/02
[PULL 29/30] tests/docker: only enable ubsan for test-clang, Paolo Bonzini, 2019/10/02