[PATCH] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()

Dan Carpenter error27 at gmail.com
Thu Dec 8 01:35:24 PST 2022


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 at 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



More information about the linux-mtd mailing list