From patchwork Sun Nov 8 23:42:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 320898 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1319774ilc; Sun, 8 Nov 2020 15:43:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2WsQQPVZF3T+gKRabAAI9M5YkKoPmUj1g7cbjIuLItQyrpRO2xpa0FW4jzyuYuNE+J+yM X-Received: by 2002:a25:e805:: with SMTP id k5mr9257183ybd.32.1604879008002; Sun, 08 Nov 2020 15:43:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604879007; cv=none; d=google.com; s=arc-20160816; b=q7NzUO3PBsH3uKCZ4qLz+Ae/j7xyy3Uh+upJMq4jpXVZeeBeKDHVaD6Dkw1VqoR8Xy XZ43tTKcAPEW/TZe/BYxMaybioHeZJRZ5sQhwDOWczdBwRbtFTK0sE6AlZqimg2X/5Dr 27m3gl3f00gZGDAlemCT9U7Zn4YgbHbHgZbSiJMN7GpD+tBgHCIqz/RNA9Q8tFoL3/s9 rl6snPvv3fLwX6zQCduOO0fFSiWS/VmUmGoFEOlWWwTXWoh2npSKbEsuOGDE8/mVakNz f5fjL6qDFXVF7oonI6DTqDtstyRVX4Y7Eb/meWutH/wB8fjXtEw09SaLMuZwzXfCMkkj 3zkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:errors-to:sender:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:cc :mime-version:references:in-reply-to:message-id:date:subject:to:from :delivered-to; bh=pZ7rBipTKKb/oioa2rrfZq9jThonQF//eO/4l0XoKyI=; b=J4uLvFMu3m2i4YULlHPxYpGKHd891tyMx9tTZ/uZg69R9pNRHEp6B4fs9PkgDwYdyo orz5mUOuBdUawpgSWMJqUtRRIPHyUn3CKnPHQxWcULHqFHKVidEnptH2TkYJCuynIoow VO7UYhh7QgLBH5dUWQ32u7ckcZUNgktXoVxOCZct/ljI/ucUGbttyKFRUCMspRwnr016 ZcywNsfdtNE7T65U2KWvzUhVeXYf8aK8TcAdJjGtKSQP5fO342Onw9vI8Pksu3KCw2v1 hEC/8vCWuWn6zft49xuaROdNDnYiO7BburVsENntiNYYdjq1RhF2sFPOedCWiqOFz9ml a/Pw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amsat.org Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com. [63.128.21.124]) by mx.google.com with ESMTPS id e186si7437684ybe.387.2020.11.08.15.43.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:43:27 -0800 (PST) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amsat.org Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-toA1CiimOr2GfgINysekyw-1; Sun, 08 Nov 2020 18:43:25 -0500 X-MC-Unique: toA1CiimOr2GfgINysekyw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E0F21006CA2; Sun, 8 Nov 2020 23:43:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB98C5C22B; Sun, 8 Nov 2020 23:43:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B9930922FA; Sun, 8 Nov 2020 23:43:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0A8Nh1Pt031639 for ; Sun, 8 Nov 2020 18:43:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0652742ACA; Sun, 8 Nov 2020 23:43:01 +0000 (UTC) Delivered-To: libvir-list@redhat.com Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 008D442AC9 for ; Sun, 8 Nov 2020 23:43:00 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCBC1858280 for ; Sun, 8 Nov 2020 23:43:00 +0000 (UTC) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-224-cH6yrOV1OqqENEe3gjZh4Q-1; Sun, 08 Nov 2020 18:42:58 -0500 X-MC-Unique: cH6yrOV1OqqENEe3gjZh4Q-1 Received: by mail-wm1-f43.google.com with SMTP id d142so6426622wmd.4 for ; Sun, 08 Nov 2020 15:42:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pZ7rBipTKKb/oioa2rrfZq9jThonQF//eO/4l0XoKyI=; b=KKx88eUgjT5iv6Gvas7jyAkBUbZ61HTCNqaR3rbR0scvl5VLOtkaHWrfkPZujJ9pme JJ+jyxtEzwuoOxFnw8ddXX8H84l3Lys8gNzaSayQTkrnxUnZpXd5ReLl5AuuFqKM5ibt 4crg2JdaLFDiFyAu+YCsrhXKtmyCKX9nChf66WFL7Mtc4cAAxSxffiFvij4SBEdSqqGH jLUnQeelU6PwImeMPu/eDG+y8adPUnA0TPujLdwZE1yPvsEMkWGXAgcibCn8PR4/qHat OEzOCo7e9SRGNPeRR+Gd3XXnvqWUKujn1s9dMywoBye8QSgG7+UXxWH8eQg1IHuDUQyu N03w== X-Gm-Message-State: AOAM532E9MzP+a8XWEIfJkus8aF7dval3z+Zm1HIlrTaPA+qze/PuWAK BTMro0CahB6nm7/XaMkQyuY= X-Received: by 2002:a1c:1c3:: with SMTP id 186mr11409605wmb.39.1604878977356; Sun, 08 Nov 2020 15:42:57 -0800 (PST) Received: from localhost.localdomain (234.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.234]) by smtp.gmail.com with ESMTPSA id q2sm5431060wru.76.2020.11.08.15.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Nov 2020 15:42:56 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 3/3] hw/mips/boston: Fix memory leak in boston_fdt_filter() error-handling paths Date: Mon, 9 Nov 2020 00:42:34 +0100 Message-Id: <20201108234234.2389789-4-f4bug@amsat.org> In-Reply-To: <20201108234234.2389789-1-f4bug@amsat.org> References: <20201108234234.2389789-1-f4bug@amsat.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Maydell , Aleksandar Rikalo , Paul Burton , libvir-list@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aurelien Jarno X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Peter Maydell Coverity points out that the error-handling paths in the boston_fdt_filter() function don't free the fdt that was allocated. Fix the leak by using g_autofree. Fixes: Coverity CID 1432275 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20201106175823.1650-1-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- hw/mips/boston.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) -- 2.26.2 diff --git a/hw/mips/boston.c b/hw/mips/boston.c index 3356d7a6814..3d40867dc4c 100644 --- a/hw/mips/boston.c +++ b/hw/mips/boston.c @@ -349,11 +349,9 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig, MachineState *machine = s->mach; const char *cmdline; int err; - void *fdt; - size_t fdt_sz, ram_low_sz, ram_high_sz; - - fdt_sz = fdt_totalsize(fdt_orig) * 2; - fdt = g_malloc0(fdt_sz); + size_t ram_low_sz, ram_high_sz; + size_t fdt_sz = fdt_totalsize(fdt_orig) * 2; + g_autofree void *fdt = g_malloc0(fdt_sz); err = fdt_open_into(fdt_orig, fdt, fdt_sz); if (err) { @@ -380,7 +378,7 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig, s->fdt_base = *load_addr; - return fdt; + return g_steal_pointer(&fdt); } static const void *boston_kernel_filter(void *opaque, const void *kernel,