Skip to contentSkip to conversation

mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()

PATCH Superseded Yuan Can 2 participants 2 messages Dec 8, 2022 Memory technology devices (MTD)

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH v2 1/1 mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()

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")
---
 drivers/mtd/parsers/tplink_safeloader.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/parsers/tplink_safeloader.c +3 -1
index f601e7bd8627..1c689dafca2a 100644
@@ -91,7 +91,7 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
 	buf = mtd_parser_tplink_safeloader_read_table(mtd);
 	if (!buf) {
 		err = -ENOENT;
-		goto err_out;
+		goto err_free_parts;
 	}
 
 	for (idx = 0, offset = TPLINK_SAFELOADER_DATA_OFFSET;
@@ -118,6 +118,8 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
 err_free:
 	for (idx -= 1; idx >= 0; idx--)
 		kfree(parts[idx].name);
+err_free_parts:
+	kfree(parts);
 err_out:
 	return err;
 };
Signature · 6 lines
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Yuan Can

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

Thanks!

regards,
dan carpenter

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