From nobody Thu Nov 6 22:54:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543930414378283.3757716092782; Tue, 4 Dec 2018 05:33:34 -0800 (PST) Received: from localhost ([::1]:56768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUApN-0001ZZ-Oi for importer@patchew.org; Tue, 04 Dec 2018 08:33:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUAmG-0007uo-Nz for qemu-devel@nongnu.org; Tue, 04 Dec 2018 08:30:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUAmC-0001C4-VT for qemu-devel@nongnu.org; Tue, 04 Dec 2018 08:30:16 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:53236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gUAm4-0000pO-ML; Tue, 04 Dec 2018 08:30:04 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gUAlu-0008CI-Ke; Tue, 04 Dec 2018 13:29:54 +0000 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 4 Dec 2018 13:29:50 +0000 Message-Id: <20181204132952.2601-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204132952.2601-1-peter.maydell@linaro.org> References: <20181204132952.2601-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 3/5] hw/sd/sdhci: Don't leak memory region in sdhci_sysbus_realize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In sdhci_sysbus_realize() we override the initialization of s->iomem that sdhci_common_realize() performs. However we don't destroy the old memory region before reinitializing it, which means that the memory allocated for mr->name in memory_region_do_init() is leaked. Since sdhci_initfn() already initializes s->io_ops to &sdhci_mmio_ops, always use that in sdhci_common_realize() and remove the now-unnecessary reinitialization of the MMIO region from sdhci_sysbus_realize(). Spotted by clang's leak sanitizer. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- hw/sd/sdhci.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 81bbf032794..83f1574ffdc 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1371,7 +1371,7 @@ static void sdhci_common_realize(SDHCIState *s, Error= **errp) s->buf_maxsz =3D sdhci_get_fifolen(s); s->fifo_buffer =3D g_malloc0(s->buf_maxsz); =20 - memory_region_init_io(&s->iomem, OBJECT(s), &sdhci_mmio_ops, s, "sdhci= ", + memory_region_init_io(&s->iomem, OBJECT(s), s->io_ops, s, "sdhci", SDHC_REGISTERS_MAP_SIZE); } =20 @@ -1565,9 +1565,6 @@ static void sdhci_sysbus_realize(DeviceState *dev, Er= ror ** errp) =20 sysbus_init_irq(sbd, &s->irq); =20 - memory_region_init_io(&s->iomem, OBJECT(s), s->io_ops, s, "sdhci", - SDHC_REGISTERS_MAP_SIZE); - sysbus_init_mmio(sbd, &s->iomem); } =20 --=20 2.19.2