From patchwork Thu May 28 15:54:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 11576259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC39A13B4 for ; Thu, 28 May 2020 15:54:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE930207F9 for ; Thu, 28 May 2020 15:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404796AbgE1Pys (ORCPT ); Thu, 28 May 2020 11:54:48 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:60384 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404774AbgE1Pyr (ORCPT ); Thu, 28 May 2020 11:54:47 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jeKrj-00056b-UX; Thu, 28 May 2020 15:54:44 +0000 From: Colin King To: Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] modpost: close file when fstat fails Date: Thu, 28 May 2020 16:54:43 +0100 Message-Id: <20200528155443.421933-1-colin.king@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Colin Ian King Currently a failed fstat error return path fails to close an open file. Fix this by setting buf to NULL and returning via the error exit path. Addresses-Coverity: ("Resource leak"); Fixes: commit 076ad831dfe8 ("modpost: add read_text_file() and get_line() helpers") Signed-off-by: Colin Ian King --- scripts/mod/modpost.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index e4691127f051..3012e5f8ec7e 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -109,8 +109,10 @@ char *read_text_file(const char *filename) if (fd < 0) return NULL; - if (fstat(fd, &st) < 0) - return NULL; + if (fstat(fd, &st) < 0) { + buf = NULL; + goto close; + } buf = NOFAIL(malloc(st.st_size + 1));