diff options
author | Andrey Smirnov <andrew.smirnov@gmail.com> | 2015-05-06 12:32:07 -0700 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-05-07 09:49:41 +0200 |
commit | 49673cfc5f67f229c80807cf582ff3f3f09b639b (patch) | |
tree | 26555170a2f53ac8ea8428a996b17589eda7864b /lib | |
parent | 6f1d94b8892ffa995b2e0ca716d82fd7efaeea18 (diff) | |
download | barebox-49673cfc5f67f229c80807cf582ff3f3f09b639b.tar.gz barebox-49673cfc5f67f229c80807cf582ff3f3f09b639b.tar.xz |
bootstrap: Fix potential memory leak in 'read_image_head'
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.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bootstrap/devfs.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c index 704680a4c9..82c7d219a2 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) |