aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAndrea Dalla Costa <andrea@dallacosta.me>2020-01-11 23:27:17 +0100
committerJo-Philipp Wich <jo@mein.io>2020-01-14 17:48:50 +0100
commitb886d3c8f3d852a5d5bfcb41f439a808d9aa2d58 (patch)
treef39ac6a3aa7675112bf303f962a0b35e62b8d77e /tools
parent8e3b3152e5402b574ff66b149cfdc6e42d61db54 (diff)
downloadupstream-b886d3c8f3d852a5d5bfcb41f439a808d9aa2d58.tar.gz
upstream-b886d3c8f3d852a5d5bfcb41f439a808d9aa2d58.tar.bz2
upstream-b886d3c8f3d852a5d5bfcb41f439a808d9aa2d58.zip
firmware-utils/mkfwimage: fix possible memory and resource leak
Add missing calls to `free` for variable `mem`. Add missing call to `fclose` for variable `f`. The same changes were made in both `mkfwimage.c` and `mkfwimage2.c`. Signed-off-by: Andrea Dalla Costa <andrea@dallacosta.me>
Diffstat (limited to 'tools')
-rw-r--r--tools/firmware-utils/src/mkfwimage.c3
-rw-r--r--tools/firmware-utils/src/mkfwimage2.c3
2 files changed, 6 insertions, 0 deletions
diff --git a/tools/firmware-utils/src/mkfwimage.c b/tools/firmware-utils/src/mkfwimage.c
index d0dca040cd..9e6d8f5b9a 100644
--- a/tools/firmware-utils/src/mkfwimage.c
+++ b/tools/firmware-utils/src/mkfwimage.c
@@ -455,6 +455,7 @@ static int build_image(image_info_t* im)
if ((f = fopen(im->outputfile, "w")) == NULL)
{
ERROR("Can not create output file: '%s'\n", im->outputfile);
+ free(mem);
return -10;
}
@@ -462,6 +463,8 @@ static int build_image(image_info_t* im)
{
ERROR("Could not write %d bytes into file: '%s'\n",
mem_size, im->outputfile);
+ free(mem);
+ fclose(f);
return -11;
}
diff --git a/tools/firmware-utils/src/mkfwimage2.c b/tools/firmware-utils/src/mkfwimage2.c
index 89a98051b4..9b7e1a3cd7 100644
--- a/tools/firmware-utils/src/mkfwimage2.c
+++ b/tools/firmware-utils/src/mkfwimage2.c
@@ -363,12 +363,15 @@ static int build_image(void)
/* write in-memory buffer into file */
if ((f = fopen(im.outputfile, "w")) == NULL) {
ERROR("Can not create output file: '%s'\n", im.outputfile);
+ free(mem);
return -10;
}
if (fwrite(mem, mem_size, 1, f) != 1) {
ERROR("Could not write %d bytes into file: '%s'\n",
mem_size, im.outputfile);
+ free(mem);
+ fclose(f);
return -11;
}