summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorShaik Shahina <shahina.shaik@intel.com>2022-11-05 01:07:06 +0530
committerMartin Roth <martin.roth@amd.corp-partner.google.com>2022-11-09 00:26:30 +0000
commit425413c35f443b422feffaee0d1ef8a091998bb6 (patch)
tree555aecb273d9fe5838dc2e29384953147fd577d1 /util
parent5c1dcd57ee642a2462d50e7fa45d97ecac5af580 (diff)
cbfstool: Fix possible memory leak
Handle the possible memory leak scenario. Foundby=klocwork BUG=NONE TEST=Boot to OS on Nivviks Change-Id: I01c4643d1e671d9bd9971ac6db8031634fffd61e Signed-off-by: Shaik Shahina <shahina.shaik@intel.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/69220 Reviewed-by: Shahina Shaik <shahina.shaik@intel.corp-partner.google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Diffstat (limited to 'util')
-rw-r--r--util/cbfstool/cbfstool.c4
-rw-r--r--util/cbfstool/common.c7
2 files changed, 8 insertions, 3 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 04b91e51ce..d26c418612 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -770,8 +770,8 @@ static int cbfs_add_master_header(void)
*/
if (param.topswap_size) {
if (update_master_header_loc_topswap(&image, h_loc,
- header_offset))
- return 1;
+ header_offset))
+ goto done;
}
ret = maybe_update_metadata_hash(&image);
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index 8ae9120acc..7154bc9d54 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -34,8 +34,13 @@ int buffer_create(struct buffer *buffer, size_t size, const char *name)
if (!buffer->data) {
fprintf(stderr, "buffer_create: Insufficient memory (0x%zx).\n",
size);
+ if (buffer->name) {
+ free(buffer->name);
+ buffer->name = NULL;
+ }
+ return -1;
}
- return (buffer->data == NULL);
+ return 0;
}
int buffer_from_file_aligned_size(struct buffer *buffer, const char *filename,