[PATCH 2/7] common: partitions: efi: fix memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux