From patchwork Tue Jun 8 09:45:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1489255 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=AImQF2bN; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzllV6Dvjz9sWF for ; Tue, 8 Jun 2021 19:47:34 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tWKVqrcKYL48M/0ypH8fR43I8agiJezoiKmFjQOrlzg=; b=AImQF2bNiHU/GA j6i9sGO0P5pUPNdjmec1x7qtzmYachm9mLxOXvhg6Esb/4IQygK+hbsQAzNZEtnABp6hUAZaCguqU Z43aF9R1OOqa/G0T/HBCySbfW205qXU3U9AtLGAtvOjfuUmuL8LUHXvLbnx18xJaCwHpwBI5HzkEV gLTJsAud7k9WVEIAtGmsBDynqY2qJaYVoBqeNtPo96uVTw5UP4zP/963PHQYPAmt4jVEmjhe9CU/H RxqkuLAR9y2FkdupbEldTh4dBaS4ox90Wy0YJF107MbfZ8xGCjK+KHXDA+snQx7wCvnUs68BGabYp OzC91eEE248dK9VW6QsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqYIZ-007Ukj-3y; Tue, 08 Jun 2021 09:45:27 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqYIU-007Uhz-OA for openwrt-devel@lists.openwrt.org; Tue, 08 Jun 2021 09:45:24 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id D600F18941; Tue, 8 Jun 2021 11:45:17 +0200 (CEST) Received: by meh.true.cz (OpenSMTPD) with ESMTP id f31d11f7; Tue, 8 Jun 2021 11:44:52 +0200 (CEST) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Cc: Kevin Darbyshire-Bryant Subject: [PATCH 21.02 02/11] firmware-utils: fix coverity zytrx.c resource leak Date: Tue, 8 Jun 2021 11:45:03 +0200 Message-Id: <20210608094512.29956-3-ynezz@true.cz> In-Reply-To: <20210608094512.29956-1-ynezz@true.cz> References: <20210608094512.29956-1-ynezz@true.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210608_024522_965954_63F7FA26 X-CRM114-Status: UNSURE ( 7.99 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Kevin Darbyshire-Bryant fix coverity resource leak warning: *len = stat.st_size; mapped = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (close(fd) < 0) CID 1484880: Resource leaks (RESOURCE_LEAK) Variable "mapped" going out of scope leaks the sto [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Kevin Darbyshire-Bryant fix coverity resource leak warning: *len = stat.st_size; mapped = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (close(fd) < 0) CID 1484880: Resource leaks (RESOURCE_LEAK) Variable "mapped" going out of scope leaks the storage it points to. return NULL; return mapped; } Signed-off-by: Kevin Darbyshire-Bryant (cherry picked from commit baf2a50ef3cf34574e12d2ab1b23578310f0d527) --- tools/firmware-utils/src/zytrx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/firmware-utils/src/zytrx.c b/tools/firmware-utils/src/zytrx.c index 302efc601065..716767920657 100644 --- a/tools/firmware-utils/src/zytrx.c +++ b/tools/firmware-utils/src/zytrx.c @@ -150,8 +150,10 @@ static void *map_input(const char *name, size_t *len) } *len = stat.st_size; mapped = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (close(fd) < 0) + if (close(fd) < 0) { + (void) munmap(mapped, stat.st_size); return NULL; + } return mapped; }