From patchwork Thu Dec 11 12:19:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 42120 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DFCF326666 for ; Thu, 11 Dec 2014 12:23:37 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id l18sf3304720wgh.10 for ; Thu, 11 Dec 2014 04:23:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=EguFQzl1UhK9NHS12HdUvj9XraNwQhr9+N1+fOsQ6tk=; b=grpUP57H0Pf/ZKLNN21GUaFiDyw12tN5R0Okjtl/bccxqqm7pWWbAKTXJAP/QjGTSY ct+41vEDom1d8zihKa5Q8vHuhVwEdm1m+2c8jF0xFe1teptFNRHx1n8XivalLVe8tiM7 foqrTSOIyzmJ/orQcz3GcJn9ssmO4eMlh98Em9IHBSUZ+QvOaINmrlqEtvsFu9sjPoSf zGHvFB05RVToHPRtCwdKvNvB5zpzhoknRI6Ce17iMQh1bIoC77PmahVcVPyuu1R5Bjx9 WPjXxzek+nALvR4wqrjMiAtnw45rrjXbfR9tnWXGnhf+rQcGc2nWBKa57PPxN4UckCSD VV4A== X-Gm-Message-State: ALoCoQnyuIzhXnsItkxp44rcGS0QFtPSWYSKH//s3IXelp5ZXpv2vGswwunC32QC+GHTQIBt3I6G X-Received: by 10.181.13.147 with SMTP id ey19mr6370039wid.2.1418300617241; Thu, 11 Dec 2014 04:23:37 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.39 with SMTP id b7ls256137lae.38.gmail; Thu, 11 Dec 2014 04:23:37 -0800 (PST) X-Received: by 10.152.5.132 with SMTP id s4mr9528463las.39.1418300617076; Thu, 11 Dec 2014 04:23:37 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id r6si1129497lae.60.2014.12.11.04.23.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 11 Dec 2014 04:23:37 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id z12so3990163lbi.32 for ; Thu, 11 Dec 2014 04:23:37 -0800 (PST) X-Received: by 10.112.16.168 with SMTP id h8mr9552926lbd.41.1418300616985; Thu, 11 Dec 2014 04:23:36 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp504309lbb; Thu, 11 Dec 2014 04:23:36 -0800 (PST) X-Received: by 10.140.18.83 with SMTP id 77mr3127112qge.56.1418300615162; Thu, 11 Dec 2014 04:23:35 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g80si956020qge.128.2014.12.11.04.23.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 11 Dec 2014 04:23:35 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:50547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz2mM-0001Cg-1E for patch@linaro.org; Thu, 11 Dec 2014 07:23:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz2j0-0004sT-KO for qemu-devel@nongnu.org; Thu, 11 Dec 2014 07:20:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xz2iz-0007Ks-7f for qemu-devel@nongnu.org; Thu, 11 Dec 2014 07:20:06 -0500 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:54567) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz2iy-0006sg-TO for qemu-devel@nongnu.org; Thu, 11 Dec 2014 07:20:05 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Xz2iq-0001Aq-Sq for qemu-devel@nongnu.org; Thu, 11 Dec 2014 12:19:56 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 11 Dec 2014 12:19:50 +0000 Message-Id: <1418300395-4348-29-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1418300395-4348-1-git-send-email-peter.maydell@linaro.org> References: <1418300395-4348-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 28/33] hw/arm/realview.c: Fix memory leak in realview_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Nikita Belov Variable 'ram_lo' is allocated unconditionally, but used only in some cases. When it is unused pointer will be lost at function exit, resulting in a memory leak. Allocate memory for 'ram_lo' only if it is needed. Valgrind output: ==16879== 240 bytes in 1 blocks are definitely lost in loss record 6,033 of 7,018 ==16879== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==16879== by 0x33D2CE: malloc_and_trace (vl.c:2804) ==16879== by 0x509E610: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4000.0) ==16879== by 0x288836: realview_init (realview.c:55) ==16879== by 0x28988C: realview_pb_a8_init (realview.c:375) ==16879== by 0x341426: main (vl.c:4413) Signed-off-by: Nikita Belov Reviewed-by: Markus Armbruster Signed-off-by: Peter Maydell --- hw/arm/realview.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/arm/realview.c b/hw/arm/realview.c index af65aa4..d41ec97 100644 --- a/hw/arm/realview.c +++ b/hw/arm/realview.c @@ -52,7 +52,7 @@ static void realview_init(MachineState *machine, CPUARMState *env; ObjectClass *cpu_oc; MemoryRegion *sysmem = get_system_memory(); - MemoryRegion *ram_lo = g_new(MemoryRegion, 1); + MemoryRegion *ram_lo; MemoryRegion *ram_hi = g_new(MemoryRegion, 1); MemoryRegion *ram_alias = g_new(MemoryRegion, 1); MemoryRegion *ram_hack = g_new(MemoryRegion, 1); @@ -135,6 +135,7 @@ static void realview_init(MachineState *machine, if (is_pb && ram_size > 0x20000000) { /* Core tile RAM. */ + ram_lo = g_new(MemoryRegion, 1); low_ram_size = ram_size - 0x20000000; ram_size = 0x20000000; memory_region_init_ram(ram_lo, NULL, "realview.lowmem", low_ram_size,