From nobody Sat Apr 11 23:04:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1773072063; cv=none; d=zohomail.com; s=zohoarc; b=Zf1hLJdKnYE356yz7qnYldy6ZXNgZFdyq4/CstrkouGjIIWhf02fI9dqkTmsnKpQDd7Ho6kT9Kt5lF4X/5Wk15Vz0CVq9ozbfgvWE0WlmyUyW8CyUby44lY7mnmXvwRHVqz3pMYJYPoPRUV3q1xHgizDaCGoTsw5nBj9bQ60mfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773072063; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=IzmpeICsmhHpjzqq103V8NsIYXc7xyq7TsCvvhiVxQY=; b=IO2XudG2wOyVVM2bIlW+Fz0tfI9sv2JlEg0agKKfStchy7i9xUemNWx9Uyh7fvLK9OMb7IEXPTZF1IAlst5U/5zIBgcl9ax93yXXe6clysa/Sbh9HELD2sozlKNnuSLx+ywu0+yN2X/UUP0d17MnOOAuDdzICLMQHfGo6TjaNwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773072063085134.32336540135873; Mon, 9 Mar 2026 09:01:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vzczr-0005ky-K0; Mon, 09 Mar 2026 11:58:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vzczP-0005EI-7p for qemu-devel@nongnu.org; Mon, 09 Mar 2026 11:57:52 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vzczN-0000se-JG for qemu-devel@nongnu.org; Mon, 09 Mar 2026 11:57:50 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4852ff06541so21347415e9.2 for ; Mon, 09 Mar 2026 08:57:49 -0700 (PDT) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48541a9c293sm781845e9.10.2026.03.09.08.57.46 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Mar 2026 08:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773071868; x=1773676668; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=IzmpeICsmhHpjzqq103V8NsIYXc7xyq7TsCvvhiVxQY=; b=B6glUdxU6nqHySWDZaI/zBB52NzAaDREW6N1dSwEg/qy4Q/qDaX0HnOORO+W9FPTBt iq4vHddObCX+5bs7KtRmXjDvOxihQkNuUiXfuKzlmwQPrMajX5pEgeEz4JqPUz3jxp6M WMTdeh+8eHdHzUOtqrK1aDBw6VjyF/cOOa1qjvMmiC6OSyQQwTeV6DbcoqAQFmFi0hzS IQHJJanzBaqo/7yzXT+3TMGh0BO++gGPjmNB3aaUBaRtvs6rOLs/EezS6SBe8Flcg6J0 JGPyG1OVm+v3PVGmXOyIdqS+TNRCfI3oj2hvI9OJ4KUMDomBV2yZ8PbT03bXmevbDweS uaVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773071868; x=1773676668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=IzmpeICsmhHpjzqq103V8NsIYXc7xyq7TsCvvhiVxQY=; b=jnmHJ93Zmq6ng7Pkv0ZP1g8sP5m4oKO6Mii6BYcQJigVQIPHO2X83gRRYwzr2Jvgaz Dr0Ri63wTLxwTQkLPAxcTIW6g0ygmV1xmjQIrT4+q2hxEZkr0YSq3b55eP9zzTlssiBG KLQE1zb0iK9rtt4/KyUkSfiGfBPf7vyekXoIPLMGHGuqnmyQRBfkkapbHIv/9eOVdl0M iBl8BFQwJTJ0L7L2dNWj6Kib+Ge6LSIhS9g4vSLwcC8hQCpR3A+u5Pkiup3DGdegPTTr FEz3V8EneFIL/OK4DfN7Wr/KDv261S8lzwUq7VeJKxFpumSU5qKx8baKpnexBh8GCEfG XWAQ== X-Gm-Message-State: AOJu0YwUsqRkDxMJL6gugaVEFiUeaMMNLAqFCCspdiube3YjkOcwGPxR ZtXPOOPIVdR7+Pq5zVh5TD7eP7UuZoXy6qHmzBBQT5yghWXbb9kVqtAzgeZ2CTGbDCPNYrc/Swf +Mp6WGJI= X-Gm-Gg: ATEYQzxDkmSO1DhxO2Sso6mI03blAlzHIOulLSJLisL7UMnjNdj1Qh3/W9bdBDENypY Ze544TybOJFrDZepBEMRP3WHVoTLCz+Q7Upm83IJIzNBbIDL2uAAtQRSZd+R6d1qpyNbx2onzuX eyvQdT4NxtpGhcDBz4elVuYO4n8NBTQIZKtzLT42tfWWJvH3hk7bZhPNiB1pSaaemVXQPuhKTKO XdBppQ0mhdPGx+48d46polcHev5d8jZfjOov6i9RH2B1abbzUqHKB+081nbzSFtVGGLzQ1cgdSS sKe6Fo1kUxs0RhBPAAIb0asJX1WkGnG3BWDJzldECilzBkHTQMZdXdMHJ/TTWooJoJ+4NXxyhLJ X24fRg1y6BPMW3+WDbxiC/Lts41Ajvvpx5WBXh3iY+nLLgbVDBaw+t69A7Hx+ybq6dp4Mep/+DT WBpSe4zN4Fop+mL5s4fVADHiIB3zYR6ZFJuTcwPIj2TUbJ5cA1kBKXcMzHVCZQdK2N0Tcgi4E6 X-Received: by 2002:a05:600c:350e:b0:480:4a90:1afe with SMTP id 5b1f17b1804b1-485269785afmr180533195e9.34.1773071867588; Mon, 09 Mar 2026 08:57:47 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 48/49] hw/misc/sifive_e_aon: Don't leak timer Date: Mon, 9 Mar 2026 16:52:18 +0100 Message-ID: <20260309155219.62400-49-philmd@linaro.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260309155219.62400-1-philmd@linaro.org> References: <20260309155219.62400-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=philmd@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1773072065317154100 From: Peter Maydell The sifive_e_aon watchdog creates a timer with timer_new_ns() in its instance_init method, but does not free it in instance_finalize. This means that QMP introspection of the device leaks it: Direct leak of 48 byte in 1 object allocated from: #0 in calloc #1 in g_malloc0 #2 in timer_new_full /home/pm215/qemu/include/qemu/timer.h:520:21 #3 in timer_new /home/pm215/qemu/include/qemu/timer.h:543:12 #4 in timer_new_ns /home/pm215/qemu/include/qemu/timer.h:563:12 #5 in sifive_e_aon_init /home/pm215/qemu/build/san/../../hw/misc/sifiv= e_e_aon.c:286:21 #6 in object_initialize_with_type /home/pm215/qemu/build/san/../../qom= /object.c:570:5 #7 in object_initialize /home/pm215/qemu/build/san/../../qom/object.c:= 578:5 #8 in object_initialize_child_with_propsv /home/pm215/qemu/build/san/.= ./../qom/object.c:608:5 #9 in object_initialize_child_with_props /home/pm215/qemu/build/san/..= /../qom/object.c:591:10 #10 in object_initialize_child_internal /home/pm215/qemu/build/san/../= ../qom/object.c:645:5 #11 in object_initialize_with_type /home/pm215/qemu/build/san/../../qo= m/object.c:570:5 #12 in object_new_with_type /home/pm215/qemu/build/san/../../qom/objec= t.c:774:5 #13 in qmp_device_list_properties /home/pm215/qemu/build/san/../../qom= /qom-qmp-cmds.c:206:11 Allocating a separate QEMUTimer with timer_new() is not the preferred interface (per the comments in include/qemu/timer.h); switch to an inline struct initialized with timer_init(), which we can clean up with timer_del() in finalize. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-ID: <20260309095129.1406506-1-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/misc/sifive_e_aon.h | 2 +- hw/misc/sifive_e_aon.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/hw/misc/sifive_e_aon.h b/include/hw/misc/sifive_e_aon.h index efa2c3023f6..e907aa7869d 100644 --- a/include/hw/misc/sifive_e_aon.h +++ b/include/hw/misc/sifive_e_aon.h @@ -46,7 +46,7 @@ struct SiFiveEAONState { MemoryRegion mmio; =20 /*< watchdog timer >*/ - QEMUTimer *wdog_timer; + QEMUTimer wdog_timer; qemu_irq wdog_irq; uint64_t wdog_restart_time; uint64_t wdogclk_freq; diff --git a/hw/misc/sifive_e_aon.c b/hw/misc/sifive_e_aon.c index 0e82ae3758b..e78f4f56725 100644 --- a/hw/misc/sifive_e_aon.c +++ b/hw/misc/sifive_e_aon.c @@ -94,9 +94,9 @@ static void sifive_e_aon_wdt_update_state(SiFiveEAONState= *r) next +=3D muldiv64((r->wdogcmp0 - wdogs) << FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, SCALE), NANOSECONDS_PER_SECOND, r->wdogclk_freq); - timer_mod(r->wdog_timer, next); + timer_mod(&r->wdog_timer, next); } else { - timer_mod(r->wdog_timer, INT64_MAX); + timer_mod(&r->wdog_timer, INT64_MAX); } } =20 @@ -283,12 +283,19 @@ static void sifive_e_aon_init(Object *obj) sysbus_init_mmio(sbd, &r->mmio); =20 /* watchdog timer */ - r->wdog_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, - sifive_e_aon_wdt_expired_cb, r); + timer_init_ns(&r->wdog_timer, QEMU_CLOCK_VIRTUAL, + sifive_e_aon_wdt_expired_cb, r); r->wdogclk_freq =3D SIFIVE_E_LFCLK_DEFAULT_FREQ; sysbus_init_irq(sbd, &r->wdog_irq); } =20 +static void sifive_e_aon_finalize(Object *obj) +{ + SiFiveEAONState *r =3D SIFIVE_E_AON(obj); + + timer_del(&r->wdog_timer); +} + static const Property sifive_e_aon_properties[] =3D { DEFINE_PROP_UINT64("wdogclk-frequency", SiFiveEAONState, wdogclk_freq, SIFIVE_E_LFCLK_DEFAULT_FREQ), @@ -307,6 +314,7 @@ static const TypeInfo sifive_e_aon_info =3D { .parent =3D TYPE_SYS_BUS_DEVICE, .instance_size =3D sizeof(SiFiveEAONState), .instance_init =3D sifive_e_aon_init, + .instance_finalize =3D sifive_e_aon_finalize, .class_init =3D sifive_e_aon_class_init, }; =20 --=20 2.53.0