OSDN Git Service

gpt_disk_get_partition_info(): free our allocations on the error path.
authorPeter Jones <pjones@redhat.com>
Mon, 1 May 2017 18:44:43 +0000 (14:44 -0400)
committerPeter Jones <pjones@redhat.com>
Mon, 1 May 2017 20:05:46 +0000 (16:05 -0400)
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 <pjones@redhat.com>
src/gpt.c

index 30cbdfd..e9c713b 100644 (file)
--- 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;
 }