From 939e4a8524821ccc30b34fec97416bc1b97b5455 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 1 May 2017 14:44:43 -0400 Subject: [PATCH 06/22] gpt_disk_get_partition_info(): free our allocations on the error path. When gpt_disk_get_partition_info() discovers that a partition is invalid, it returns error, but it forgets to free its allocations. Found by covscan. Signed-off-by: Peter Jones --- src/gpt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/gpt.c b/src/gpt.c index 30cbdfd..e9c713b 100644 --- a/src/gpt.c +++ b/src/gpt.c @@ -640,7 +640,7 @@ gpt_disk_get_partition_info(int fd, uint32_t num, uint64_t * start, gpt_entry *ptes = NULL, *p; int rc = 0; - char *report=getenv("LIBEFIBOOT_REPORT_GPT_ERRORS"); + char *report = getenv("LIBEFIBOOT_REPORT_GPT_ERRORS"); if (report) report_errors = 1; @@ -662,12 +662,10 @@ gpt_disk_get_partition_info(int fd, uint32_t num, uint64_t * start, if (report_errors) fprintf(stderr, "partition %d is not valid\n", num); errno = EINVAL; - return -1; + rc = -1; } - if (ptes) - free(ptes); - if (gpt) - free(gpt); + free(ptes); + free(gpt); return rc; } -- 2.12.2