From: Lukas Bulwahn <lukas.bulwahn@gmail.com>
To: linux-kbuild@vger.kernel.org
Cc: Alexey Dobriyan <adobriyan@gmail.com>,
lukas.bulwahn@gmail.com, sil2review@lists.osadl.org,
Masahiro Yamada <yamada.masahiro@socionext.com>,
Michal Marek <michal.lkml@markovi.net>,
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 [thread overview]
Message-ID: <1513281250-9186-2-git-send-email-lukas.bulwahn@gmail.com> (raw)
In-Reply-To: <1513281250-9186-1-git-send-email-lukas.bulwahn@gmail.com>
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 <lukas.bulwahn@gmail.com>
---
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';
--
2.7.4
next prev parent reply other threads:[~2017-12-14 19:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-14 19:54 Applying Facebook's static analysis tool Infer Lukas Bulwahn
2017-12-14 19:54 ` Lukas Bulwahn [this message]
2017-12-15 8:23 ` [SIL2review] [PATCH] fixdep: free memory on second error path of do_config_file Nicholas Mc Guire
2017-12-18 13:58 ` Masahiro Yamada
2017-12-27 12:39 ` Lukas Bulwahn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1513281250-9186-2-git-send-email-lukas.bulwahn@gmail.com \
--to=lukas.bulwahn@gmail.com \
--cc=adobriyan@gmail.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.lkml@markovi.net \
--cc=sil2review@lists.osadl.org \
--cc=yamada.masahiro@socionext.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®