From: Andrew Morton <akpm@linux-foundation.org>
To: linfeilong <linfeilong@huawei.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] scripts: fix memleak error in read_file
Date: Tue, 22 Oct 2019 15:13:05 -0700 [thread overview]
Message-ID: <20191022151305.c4af5c45ee7c605b4b12ae32@linux-foundation.org> (raw)
In-Reply-To: <bf5c73b4b8534189be0f0df81fe863f0@huawei.com>
On Tue, 22 Oct 2019 11:47:59 +0000 linfeilong <linfeilong@huawei.com> wrote:
> An error is found by the static code analysis tool: "memleak"
> Fix this by add free before return.
>
> Signed-off-by: Feilong Lin <linfeilong@huawei.com>
> ---
> scripts/insert-sys-cert.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/scripts/insert-sys-cert.c b/scripts/insert-sys-cert.c
> index 8902836..22d99a8 100644
> --- a/scripts/insert-sys-cert.c
> +++ b/scripts/insert-sys-cert.c
> @@ -250,6 +250,7 @@ static char *read_file(char *file_name, int *size)
> }
> if (read(fd, buf, *size) != *size) {
> perror("File read failed");
> + free(buf);
> close(fd);
> return NULL;
> }
A few lines later we do
return buf;
so the patch adds a use-after-free error.
We could do a free(cert) down in main() or we could just do nothing -
read_file() is only called a single time.
next prev parent reply other threads:[~2019-10-22 22:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-22 11:47 [PATCH] scripts: fix memleak error in read_file linfeilong
2019-10-22 22:13 ` Andrew Morton [this message]
2019-10-23 2:56 ` 答复: " linfeilong
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=20191022151305.c4af5c45ee7c605b4b12ae32@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linfeilong@huawei.com \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).