From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>, qemu-arm@nongnu.org
Subject: [PATCH] hw/misc/bcm2835_powermgt: Free timer during finalize to avoid memory leak
Date: Thu, 10 Sep 2026 19:50:01 +0200 [thread overview]
Message-ID: <20260910175001.76278-1-thuth@redhat.com> (raw)
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 <thuth@redhat.com>
---
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
next reply other threads:[~2026-09-10 17:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 17:50 Thomas Huth [this message]
2026-09-14 9:30 ` [PATCH] hw/misc/bcm2835_powermgt: Free timer during finalize to avoid memory leak Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260910175001.76278-1-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox