When running e.g. the device-introspect-test with valgrind, there are
reports that the code in bcm2835_powermgt.c leaks memory like this:
48 bytes in 1 blocks are definitely lost in loss record 2,090 of 4,315
at 0x6B4B62B: calloc (vg_replace_malloc.c:1616)
by 0x7AFF6E1: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.8800.3)
by 0x42B1E48: timer_new_full (timer.h:520)
by 0x42B1E48: timer_new (timer.h:543)
by 0x42B1E48: timer_new_ns (timer.h:563)
by 0x42B1E48: bcm2835_powermgt_init (bcm2835_powermgt.c:151)
by 0x48632E3: object_init_with_type (object.c:426)
by 0x48632E3: object_initialize_with_type (object.c:508)
by 0x48636BE: object_new_with_type (object.c:706)
by 0x4962FF1: qmp_device_list_properties (qom-qmp-cmds.c:206)
by 0x44ACB90: qdev_device_help (qdev-monitor.c:315)
by 0x44AE14E: hmp_device_add (qdev-monitor.c:1018)
Free the timer during finalize() to avoid this problem.
Signed-off-by: Thomas Huth <[email protected]>
---
hw/misc/bcm2835_powermgt.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/hw/misc/bcm2835_powermgt.c b/hw/misc/bcm2835_powermgt.c
index 7b01be48bb7..e31fcb1f131 100644
--- a/hw/misc/bcm2835_powermgt.c
+++ b/hw/misc/bcm2835_powermgt.c
@@ -152,6 +152,14 @@ static void bcm2835_powermgt_init(Object *obj)
bcm2835_powermgt_expire, s);
}
+static void bcm2835_powermgt_finalize(Object *obj)
+{
+ BCM2835PowerMgtState *s = BCM2835_POWERMGT(obj);
+
+ timer_free(s->wdog_timer);
+ s->wdog_timer = NULL;
+}
+
static void bcm2835_powermgt_reset(DeviceState *dev)
{
BCM2835PowerMgtState *s = BCM2835_POWERMGT(dev);
@@ -177,6 +185,7 @@ static const TypeInfo bcm2835_powermgt_info = {
.instance_size = sizeof(BCM2835PowerMgtState),
.class_init = bcm2835_powermgt_class_init,
.instance_init = bcm2835_powermgt_init,
+ .instance_finalize = bcm2835_powermgt_finalize,
};
static void bcm2835_powermgt_register_types(void)
--
2.55.0