summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Georgi <patrick@georgi-clan.de>2014-09-29 10:08:35 +0200
committerPatrick Georgi <pgeorgi@google.com>2014-10-18 14:45:15 +0200
commit96990a285d775520c6279603371a1394bcdd8cd3 (patch)
treea9b2c9eb3e2ed0f3dbfb5e2b83eee6b97c4f1a71
parent747c07f08a839f5b2b6220f2e61fdf99b9ff35eb (diff)
downloadcoreboot-96990a285d775520c6279603371a1394bcdd8cd3.tar.xz
cbfstool: free memory
Change-Id: Ic53127a61154460fa3741a92a3b2de0eba446e9f Found-by: Coverity Scan Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-on: http://review.coreboot.org/6987 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
-rw-r--r--util/cbfstool/cbfs-mkpayload.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c
index dabe32262b..38cc482d22 100644
--- a/util/cbfstool/cbfs-mkpayload.c
+++ b/util/cbfstool/cbfs-mkpayload.c
@@ -79,8 +79,9 @@ int parse_elf_to_payload(const struct buffer *input,
int segments = 1;
int isize = 0, osize = 0;
int doffset = 0;
- struct cbfs_payload_segment *segs;
+ struct cbfs_payload_segment *segs = NULL;
int i;
+ int ret = 0;
comp_func_ptr compress = compression_function(algo);
if (!compress)
@@ -133,12 +134,16 @@ int parse_elf_to_payload(const struct buffer *input,
}
/* allocate the segment header array */
segs = calloc(segments, sizeof(*segs));
- if (segs == NULL)
- return -1;
+ if (segs == NULL) {
+ ret = -1;
+ goto out;
+ }
/* Allocate a block of memory to store the data in */
if (buffer_create(output, (segments * sizeof(*segs)) + isize,
- input->name) != 0)
- return -1;
+ input->name) != 0) {
+ ret = -1;
+ goto out;
+ }
memset(output->data, 0, output->size);
doffset = (segments * sizeof(*segs));
@@ -208,7 +213,8 @@ int parse_elf_to_payload(const struct buffer *input,
if (compress((char *)&header[phdr[i].p_offset],
phdr[i].p_filesz, output->data + doffset, &len)) {
buffer_delete(output);
- return -1;
+ ret = -1;
+ goto out;
}
segs[segments].len = len;
@@ -233,7 +239,12 @@ int parse_elf_to_payload(const struct buffer *input,
output->size = (segments * sizeof(*segs)) + osize;
xdr_segs(output, segs, segments);
- return 0;
+
+out:
+ if (segs) free(segs);
+ if (shdr) free(shdr);
+ if (phdr) free(phdr);
+ return ret;
}
int parse_flat_binary_to_payload(const struct buffer *input,