hw/misc/bcm2835_powermgt: Free timer during finalize to avoid memory leak
Subsystems (2)
PATCH 1/1 hw/misc/bcm2835_powermgt: Free timer during finalize to avoid memory leak
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(+)
hw/misc/bcm2835_powermgt.c +9 -0
@@ -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 )
Signature · 1 line
2.55.0
Peter Maydell
AppliedQuoted 18 lines · Thomas Huth
When running e.g. the device-introspect-test with valgrind, there are reports that the code in
bcm2835_powermgt.cleaks 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)
Quoted 4 lines
Free the timer during
finalize()to avoid this problem.Signed-off-by Thomas Huth <[email protected]>---
Applied to target-arm.next, thanks.
-- PMM