linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()
@ 2022-12-08  8:38 Yuan Can
  2022-12-08  9:35 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Yuan Can @ 2022-12-08  8:38 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, rafal, error27, linux-mtd; +Cc: yuancan

The parts needs to be freed with all its elements, otherwise it will be
leaked.

Fixes: 00a3588084be ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/mtd/parsers/tplink_safeloader.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/parsers/tplink_safeloader.c b/drivers/mtd/parsers/tplink_safeloader.c
index f601e7bd8627..860339461905 100644
--- a/drivers/mtd/parsers/tplink_safeloader.c
+++ b/drivers/mtd/parsers/tplink_safeloader.c
@@ -118,6 +118,7 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
 err_free:
 	for (idx -= 1; idx >= 0; idx--)
 		kfree(parts[idx].name);
+	kfree(parts);
 err_out:
 	return err;
 };
-- 
2.17.1


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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()
  2022-12-08  8:38 [PATCH] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse() Yuan Can
@ 2022-12-08  9:35 ` Dan Carpenter
  2022-12-08 11:26   ` Yuan Can
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2022-12-08  9:35 UTC (permalink / raw)
  To: Yuan Can; +Cc: miquel.raynal, richard, vigneshr, rafal, linux-mtd

On Thu, Dec 08, 2022 at 08:38:59AM +0000, Yuan Can wrote:
> The parts needs to be freed with all its elements, otherwise it will be
> leaked.
> 
> Fixes: 00a3588084be ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
>  drivers/mtd/parsers/tplink_safeloader.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mtd/parsers/tplink_safeloader.c b/drivers/mtd/parsers/tplink_safeloader.c
> index f601e7bd8627..860339461905 100644
> --- a/drivers/mtd/parsers/tplink_safeloader.c
> +++ b/drivers/mtd/parsers/tplink_safeloader.c
> @@ -118,6 +118,7 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
>  err_free:
>  	for (idx -= 1; idx >= 0; idx--)
>  		kfree(parts[idx].name);
> +	kfree(parts);
>  err_out:

This still leaves a leak if mtd_parser_tplink_safeloader_read_table()
fails.  Create a new label and update the goto.

err_free:
 	for (idx -= 1; idx >= 0; idx--)
 		kfree(parts[idx].name);
err_free_parts:
	kfree(parts);
err_out:
	return err;

regards,
dan carpenter

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()
  2022-12-08  9:35 ` Dan Carpenter
@ 2022-12-08 11:26   ` Yuan Can
  0 siblings, 0 replies; 3+ messages in thread
From: Yuan Can @ 2022-12-08 11:26 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: miquel.raynal, richard, vigneshr, rafal, linux-mtd


在 2022/12/8 17:35, Dan Carpenter 写道:
> On Thu, Dec 08, 2022 at 08:38:59AM +0000, Yuan Can wrote:
>> The parts needs to be freed with all its elements, otherwise it will be
>> leaked.
>>
>> Fixes: 00a3588084be ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
>> Signed-off-by: Yuan Can <yuancan@huawei.com>
>> ---
>>   drivers/mtd/parsers/tplink_safeloader.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/mtd/parsers/tplink_safeloader.c b/drivers/mtd/parsers/tplink_safeloader.c
>> index f601e7bd8627..860339461905 100644
>> --- a/drivers/mtd/parsers/tplink_safeloader.c
>> +++ b/drivers/mtd/parsers/tplink_safeloader.c
>> @@ -118,6 +118,7 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
>>   err_free:
>>   	for (idx -= 1; idx >= 0; idx--)
>>   		kfree(parts[idx].name);
>> +	kfree(parts);
>>   err_out:
> This still leaves a leak if mtd_parser_tplink_safeloader_read_table()
> fails.  Create a new label and update the goto.
>
> err_free:
>   	for (idx -= 1; idx >= 0; idx--)
>   		kfree(parts[idx].name);
> err_free_parts:
> 	kfree(parts);
> err_out:
> 	return err;
Thanks for pointing out this! will be fixed in the next version.

-- 
Best regards,
Yuan Can


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-08 11:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08  8:38 [PATCH] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse() Yuan Can
2022-12-08  9:35 ` Dan Carpenter
2022-12-08 11:26   ` Yuan Can

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).