From patchwork Thu Dec 14 19:54:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Bulwahn X-Patchwork-Id: 10113219 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 26D5F60327 for ; Thu, 14 Dec 2017 19:56:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1674C29073 for ; Thu, 14 Dec 2017 19:56:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A7772907E; Thu, 14 Dec 2017 19:56:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 915AA29073 for ; Thu, 14 Dec 2017 19:56:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752298AbdLNT4q (ORCPT ); Thu, 14 Dec 2017 14:56:46 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:41173 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752045AbdLNT4m (ORCPT ); Thu, 14 Dec 2017 14:56:42 -0500 Received: by mail-wr0-f194.google.com with SMTP id z18so6148980wrb.8; Thu, 14 Dec 2017 11:56:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+JVJd7HZKELooHLZYp4W/Rq5k1uhgZsEXjvueWBtDFM=; b=fw22FfD6YR6RYqlTCEjEQlPtuHSejJf/9wbd1qER1hnbDwGfLQC7jpcWi8nsHrRT42 AgvOUm4HH84fFlBHdh3j38MjgRPNi06VXlPARuje8tk4vC4oDp+Cxtk2y+P4ajGUpeYa 1nRj60p80t78WmoKfre3mCjy+z1XRPAHP/sBRejogplcaOoWB9i9IIgNo8trm2ZLpiJa xYLYJZ9KwigdL6PNvNBmw8TUtaw5j3dSsK17yQWvxE2EoQF1N4MynxO4QOdNW1v6/FBc U0uNwM8SjyI4YcRekswB2yvwZ7GJxmN0pwPdxY+SBtjRfBp8cpFsEUfCkD29ny2SFd/V TGEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+JVJd7HZKELooHLZYp4W/Rq5k1uhgZsEXjvueWBtDFM=; b=n8UGGEMD9x+hg3MTmILBXaewCmaxt/Y0xhGpR/TYwR6hTVcrEVwSGl57VDKtKD9om8 Qtl0EZM8S7XshfI/+ujrYGRpARBhUaBkf+4vtVGTH5KmlOL/BfyTBv1vR+Fi75Po5Yez KLrm7q8abOisPjKS6GVLpcPLHMbdkMQZinCPwxDRaBrCzY97Kca5H/DPreRVvcFjpQPf 5s5uAcOi3yQbQqplRjj1ec2fEbeek7BTwS0YG5yPhH9Thh3PfcbUxMvsbDOrLeorttgK duVIgh8QErut4PeRyvQYpiri7gZx2I7xaYVbcVxFw6Uns3WrTK1vGC5nUUvBiQ/2yehC mlFg== X-Gm-Message-State: AKGB3mIf/DSWO34wSVumuWTKT0DfMu5ZYMPFDwVEUpNwWRTdcFtpuIdR BltB1ECh07Pm3zIZEOHXjKKeHAX7 X-Google-Smtp-Source: ACJfBot54iYfJ+NlKT/rGOtMCbj1Jkicz/9+mC0RyyJvytA2ZLcBiCuxFV9GeIAFOcTV0rtnK1vlqA== X-Received: by 10.223.164.84 with SMTP id e20mr7034806wra.52.1513281401325; Thu, 14 Dec 2017 11:56:41 -0800 (PST) Received: from hsp.bmw-carit.intra ([145.253.130.2]) by smtp.gmail.com with ESMTPSA id a5sm3020535wra.87.2017.12.14.11.56.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Dec 2017 11:56:40 -0800 (PST) From: Lukas Bulwahn To: linux-kbuild@vger.kernel.org Cc: Alexey Dobriyan , lukas.bulwahn@gmail.com, sil2review@lists.osadl.org, Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH] fixdep: free memory on second error path of do_config_file Date: Thu, 14 Dec 2017 20:54:10 +0100 Message-Id: <1513281250-9186-2-git-send-email-lukas.bulwahn@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513281250-9186-1-git-send-email-lukas.bulwahn@gmail.com> References: <1513281250-9186-1-git-send-email-lukas.bulwahn@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit dee81e988674 ("fixdep: faster CONFIG_ search") introduces the memory leak when `map = mmap(...)` was replaced with `map = malloc(...)` and `read(fd, map, ...)`. It introduces a new second error path, which does not free the allocated memory for `map`. We now correct that behavior and free `map` before the do_config_file() function returns. Facebook's static analysis tool Infer (http://fbinfer.com) found this memory leak: scripts/basic/fixdep.c:297: error: MEMORY_LEAK memory dynamically allocated by call to `malloc()` at line 290, \ column 8 is not reachable after line 297, column 3. Fixes: dee81e988674 ("fixdep: faster CONFIG_ search") Signed-off-by: Lukas Bulwahn Reviewed-by: Nicholas Mc Guire --- scripts/basic/fixdep.c | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index bbf62cb..131c450 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -296,6 +296,7 @@ static void do_config_file(const char *filename) if (read(fd, map, st.st_size) != st.st_size) { perror("fixdep: read"); close(fd); + free(map); return; } map[st.st_size] = '\0';