aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src
diff options
context:
space:
mode:
authorAndrea Dalla Costa <andrea@dallacosta.me>2020-01-11 22:57:58 +0100
committerPetr Štetiar <ynezz@true.cz>2020-07-08 16:07:05 +0200
commitd64b20da21d796334840fe9614bb0cb572e22fda (patch)
tree0c48500751900a2b84e0ac2c7c8c20c2e45f1a3c /tools/firmware-utils/src
parent4a77a060ab6219f830390cd53c2817b621f39760 (diff)
downloadupstream-d64b20da21d796334840fe9614bb0cb572e22fda.tar.gz
upstream-d64b20da21d796334840fe9614bb0cb572e22fda.tar.bz2
upstream-d64b20da21d796334840fe9614bb0cb572e22fda.zip
firmware-utils/hcsmakeimage: fix possible memory leak and resource leaks
Add missing calls to `free` for variable `filebuffer`. Add missing calls to `fclose` for variables `fd` and `fd_out`. Signed-off-by: Andrea Dalla Costa <andrea@dallacosta.me>
Diffstat (limited to 'tools/firmware-utils/src')
-rw-r--r--tools/firmware-utils/src/hcsmakeimage.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/firmware-utils/src/hcsmakeimage.c b/tools/firmware-utils/src/hcsmakeimage.c
index 7baa7b5845..2888810cc7 100644
--- a/tools/firmware-utils/src/hcsmakeimage.c
+++ b/tools/firmware-utils/src/hcsmakeimage.c
@@ -183,6 +183,7 @@ int main ( int argc, char** argv )
char* filebuffer = malloc ( buf.st_size+10 );
FILE* fd = fopen ( input,"r" );
fread ( filebuffer, 1, buf.st_size,fd );
+ fclose (fd);
if (!output)
{
output = malloc(strlen(input+5));
@@ -194,10 +195,13 @@ int main ( int argc, char** argv )
if (!fd_out)
{
fprintf(stderr, "Failed to open output file: %s\n", output);
+ free(filebuffer);
exit(1);
}
fwrite ( head,1,sizeof ( ldr_header_t ),fd_out );
fwrite ( filebuffer,1,buf.st_size,fd_out );
printf("Firmware image %s is ready\n", output);
+ free(filebuffer);
+ fclose(fd_out);
return 0;
}