diff options
author | Patrick Georgi <pgeorgi@google.com> | 2019-07-30 15:39:19 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-31 00:40:19 +0000 |
commit | 45f3a39e6b8a56098c68e0c40604832f016d7285 (patch) | |
tree | 82b25ac4b707f3c19029dd4a98702ec7e584486b /util/cbi-util.c | |
parent | 89712b28fa3fcf6005fa99ff4201e4ece82d87f4 (diff) | |
download | chrome-ec-45f3a39e6b8a56098c68e0c40604832f016d7285.tar.gz |
util/cbi-util.c: free memory in error cases
BUG=none
BRANCH=none
TEST=none
Change-Id: Idc8ad893403b1efec818f812f730cbaf5ed4dbf6
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Found-by: Coverity Scan #187040, #187042
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1725953
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Auto-Submit: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
Diffstat (limited to 'util/cbi-util.c')
-rw-r--r-- | util/cbi-util.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/util/cbi-util.c b/util/cbi-util.c index fbf0a6068b..1027c820cc 100644 --- a/util/cbi-util.c +++ b/util/cbi-util.c @@ -348,11 +348,11 @@ static int cmd_create(int argc, char **argv) /* Output image */ rv = write_file(filename, cbi, size); + free(cbi); if (rv) { fprintf(stderr, "Unable to write CBI image to %s\n", filename); return rv; } - free(cbi); fprintf(stderr, "CBI image is created successfully\n"); @@ -447,11 +447,13 @@ static int cmd_show(int argc, char **argv) if (memcmp(h->magic, cbi_magic, sizeof(cbi_magic))) { fprintf(stderr, "Invalid Magic\n"); + free(buf); return -1; } if (cbi_crc8(h) != h->crc) { fprintf(stderr, "Invalid CRC\n"); + free(buf); return -1; } |