[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 5/6] hw/misc/mos6522: move timer_new from init() into realize(
From: |
Pan Nengyuan |
Subject: |
[PATCH v3 5/6] hw/misc/mos6522: move timer_new from init() into realize() to avoid memleaks |
Date: |
Thu, 27 Feb 2020 10:50:54 +0800 |
There are some memleaks when we call 'device_list_properties'. This patch move
timer_new from init into realize to fix it.
Meanwhile, add calls to mos6522_realize() in mac_via_realize to make this move
to be valid.
Reported-by: Euler Robot <address@hidden>
Signed-off-by: Pan Nengyuan <address@hidden>
---
Cc: Laurent Vivier <address@hidden>
---
v2->v1:
- no changes in this patch.
v3->v2:
- remove null check in reset, and add calls to mos6522_realize() in
mac_via_realize to make this move to be valid.
---
hw/misc/mac_via.c | 5 +++++
hw/misc/mos6522.c | 6 ++++++
2 files changed, 11 insertions(+)
diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
index b7d0012794..1d72d4ef35 100644
--- a/hw/misc/mac_via.c
+++ b/hw/misc/mac_via.c
@@ -879,6 +879,11 @@ static void mac_via_realize(DeviceState *dev, Error **errp)
sysbus_init_child_obj(OBJECT(dev), "via2", &m->mos6522_via2,
sizeof(m->mos6522_via2), TYPE_MOS6522_Q800_VIA2);
+ object_property_set_bool(OBJECT(&m->mos6522_via1), true, "realized",
+ &error_abort);
+ object_property_set_bool(OBJECT(&m->mos6522_via2), true, "realized",
+ &error_abort);
+
/* Pass through mos6522 output IRQs */
ms = MOS6522(&m->mos6522_via1);
object_property_add_alias(OBJECT(dev), "irq[0]", OBJECT(ms),
diff --git a/hw/misc/mos6522.c b/hw/misc/mos6522.c
index 19e154b870..c1cd154a84 100644
--- a/hw/misc/mos6522.c
+++ b/hw/misc/mos6522.c
@@ -485,6 +485,11 @@ static void mos6522_init(Object *obj)
for (i = 0; i < ARRAY_SIZE(s->timers); i++) {
s->timers[i].index = i;
}
+}
+
+static void mos6522_realize(DeviceState *dev, Error **errp)
+{
+ MOS6522State *s = MOS6522(dev);
s->timers[0].timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, mos6522_timer1, s);
s->timers[1].timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, mos6522_timer2, s);
@@ -502,6 +507,7 @@ static void mos6522_class_init(ObjectClass *oc, void *data)
dc->reset = mos6522_reset;
dc->vmsd = &vmstate_mos6522;
+ dc->realize = mos6522_realize;
device_class_set_props(dc, mos6522_properties);
mdc->parent_reset = dc->reset;
mdc->set_sr_int = mos6522_set_sr_int;
--
2.18.2
- [PATCH v3 0/6] delay timer_new from init to realize to fix memleaks., Pan Nengyuan, 2020/02/26
- [PATCH v3 4/6] hw/arm/strongarm: move timer_new from init() into realize() to avoid memleaks, Pan Nengyuan, 2020/02/26
- [PATCH v3 3/6] hw/arm/spitz: move timer_new from init() into realize() to avoid memleaks, Pan Nengyuan, 2020/02/26
- [PATCH v3 2/6] hw/arm/pxa2xx: move timer_new from init() into realize() to avoid memleaks, Pan Nengyuan, 2020/02/26
- [PATCH v3 6/6] hw/timer/cadence_ttc: move timer_new from init() into realize() to avoid memleaks, Pan Nengyuan, 2020/02/26
- [PATCH v3 5/6] hw/misc/mos6522: move timer_new from init() into realize() to avoid memleaks,
Pan Nengyuan <=
- [PATCH v3 1/6] s390x: fix memleaks in cpu_finalize, Pan Nengyuan, 2020/02/26
Re: [PATCH v3 1/6] s390x: fix memleaks in cpu_finalize, Cornelia Huck, 2020/02/27