public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: <ant.v.moryakov@gmail.com>, <linux-mtd@lists.infradead.org>
Subject: Re: [PATCH] ubifs-utils: common: fix memory leak in devtable.c
Date: Fri, 25 Apr 2025 11:22:25 +0800	[thread overview]
Message-ID: <e3b58d69-ca9a-2201-ae8b-e5a7e51bcd2e@huawei.com> (raw)
In-Reply-To: <20250424181922.17531-1-ant.v.moryakov@gmail.com>

在 2025/4/25 2:19, ant.v.moryakov@gmail.com 写道:
> From: AntonMoryakov <ant.v.moryakov@gmail.com>
> 
> Report of the static analyzer:
> Dynamic memory, referenced by 'line', is allocated at devtable.c:356
> by calling function 'getline' and lost at devtable.c:388.
> (line: while (getline(&line, &len, f) != -1) {)
> 
> Correct explained:
> Now line is freed in any exit scenario via out_close which eliminates this error.
> 
> Triggers found by static analyzer Svace.
> 
> Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.co
> 
> ---
>   ubifs-utils/common/devtable.c | 1 +
>   1 file changed, 1 insertion(+)


According to the realization of getline[1], feel free to add:

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>

[1] https://github.com/bminor/glibc/blob/master/libio/iogetdelim.c#L40
> 
> diff --git a/ubifs-utils/common/devtable.c b/ubifs-utils/common/devtable.c
> index 7347f09..2e581ff 100644
> --- a/ubifs-utils/common/devtable.c
> +++ b/ubifs-utils/common/devtable.c
> @@ -392,6 +392,7 @@ int parse_devtable(const char *tbl_file)
>   
>   out_close:
>   	fclose(f);
> +	free(line);
>   	free_devtable_info();
>   	return -1;
>   }
> 


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2025-04-25  3:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-24 18:19 [PATCH] ubifs-utils: common: fix memory leak in devtable.c ant.v.moryakov
2025-04-25  3:22 ` Zhihao Cheng [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-05-15  8:25 Anton Moryakov
2025-06-02  5:35 ` David Oberhollenzer

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=e3b58d69-ca9a-2201-ae8b-e5a7e51bcd2e@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=ant.v.moryakov@gmail.com \
    --cc=linux-mtd@lists.infradead.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