Original version of 'read_image_head' would not free the memory
allocated for barebox header in cases of any failure. Fix this by
adding a dedicated resourse de-allocation code path.

Signed-off-by: Andrey Smirnov <andrew.smir...@gmail.com>
---
 lib/bootstrap/devfs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c
index 704680a..82c7d21 100644
--- a/lib/bootstrap/devfs.c
+++ b/lib/bootstrap/devfs.c
@@ -35,7 +35,7 @@ static void *read_image_head(const char *name)
        cdev = cdev_open(name, O_RDONLY);
        if (!cdev) {
                bootstrap_err("failed to open partition\n");
-               return NULL;
+               goto free_header;
        }

        ret = cdev_read(cdev, header, BAREBOX_HEAD_SIZE, 0, 0);
@@ -43,10 +43,14 @@ static void *read_image_head(const char *name)

        if (ret != BAREBOX_HEAD_SIZE) {
                bootstrap_err("failed to read from partition\n");
-               return NULL;
+               goto free_header;
        }

        return header;
+
+free_header:
+       free(header);
+       return NULL;
 }

 static unsigned int get_image_size(void *head)
--
2.1.4

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to