[PATCH 2/7] common: partitions: efi: fix memory leak
Sascha Hauer
s.hauer at pengutronix.de
Wed Feb 14 23:47:52 PST 2024
In efi_partition() gpt and ptes is allocated but never freed. It's no
longer used when leaving this function, so free the memory before
leaving it.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
common/partitions/efi.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 0add66e6e4..d0e14d5abb 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -440,11 +440,8 @@ static void efi_partition(void *buf, struct block_device *blk,
int nb_part;
struct partition *pentry;
- if (!find_valid_gpt(buf, blk, &gpt, &ptes) || !gpt || !ptes) {
- kfree(gpt);
- kfree(ptes);
- return;
- }
+ if (!find_valid_gpt(buf, blk, &gpt, &ptes) || !gpt || !ptes)
+ goto out;
snprintf(blk->cdev.diskuuid, sizeof(blk->cdev.diskuuid), "%pUl", &gpt->disk_guid);
dev_add_param_string_fixed(blk->dev, "guid", blk->cdev.diskuuid);
@@ -474,6 +471,9 @@ static void efi_partition(void *buf, struct block_device *blk,
pentry->typeuuid = ptes[i].partition_type_guid;
pd->used_entries++;
}
+out:
+ kfree(gpt);
+ kfree(ptes);
}
static struct partition_parser efi_partition_parser = {
--
2.39.2
More information about the barebox
mailing list