From patchwork Tue Dec 4 13:29:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 152811 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8069283ljp; Tue, 4 Dec 2018 05:29:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/UBY5mASSspF1l/U/8XvnRGb8X/xJsYaBHkdfCA4OhTRuzQdsIgNeY7CmDoIejZkohAXloU X-Received: by 2002:a1c:d988:: with SMTP id q130mr12927654wmg.41.1543930195162; Tue, 04 Dec 2018 05:29:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543930195; cv=none; d=google.com; s=arc-20160816; b=gH9GBlkvHBew/thhvGodorpsPG2ic1Zvx33pNuNkGbW8FKCNxRhw0XDfi5+KVZt1dj i04aU+48vbtqDAp9IUbf1LGJI6Ko6O+EiVLtSGB2LNXlpBBxiBQ41+o/JMYk+9s2sJMR z8FukM5hbR4w9yoQiVO/RWuz3wDAfeHaH6ljls66ccgtilY/aPmGZvtws0bdiUXJ1sZc BvpLwIdfIbJ1PvAAEeReRQ3gwf3uGkfgClIs+zJ/2GD9eJnxIigYkOJtX57V/Oi+eRNh FbB/cXTbRKPd8HZY/tLzXKwYE6NSJDiuh4zlKzTz6gB8f1YDW5MFCzefTMlCJovTF2Oi zalQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=mamUj2zWB24ciEZclPxo44bBVi9Ux6pp4DxcjmW26iQ=; b=Y3BgPf5bcWiVXUO3V97KejeTccmKsR6jbOqeaZlpOm/uaqKj4YZ3FvSs+cE59o43l+ McSwQtnm5H4PiJrkyDKN9iMiDuphjle3MPklch8qPaAD1HtOgnHLTh9eySTzlG91ZMlu OakDtFmAj+W3ZeM4BaCNXbNPlcxOZVD4h9+MbndVlgi35YDL4DdzD57UHgFNLAoZVAO7 8rY/xIwYHi45h1qX7TF1MOjukUSXIDqlxNFpIU8C/H/9rYv5ZNcI6cErOxgQN1RS4TO3 8g7h+deB6AuRTx5tXqhm8n+7eOuBeBMTvWt1e2XfZdQ2tlFR9oq59tyC9E7JEvQk/46r PCRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id n25si11425131wra.167.2018.12.04.05.29.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 05:29:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 Cc: patches@linaro.org Subject: [PATCH 3/5] hw/sd/sdhci: Don't leak memory region in sdhci_sysbus_realize() 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 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 --- hw/sd/sdhci.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) -- 2.19.2 Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé 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 = sdhci_get_fifolen(s); s->fifo_buffer = g_malloc0(s->buf_maxsz); - 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); } @@ -1565,9 +1565,6 @@ static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp) sysbus_init_irq(sbd, &s->irq); - memory_region_init_io(&s->iomem, OBJECT(s), s->io_ops, s, "sdhci", - SDHC_REGISTERS_MAP_SIZE); - sysbus_init_mmio(sbd, &s->iomem); }