From 39850fc681c235639da0f80b3f0d3771a319daac Mon Sep 17 00:00:00 2001 From: Andrea Dalla Costa Date: Sat, 11 Jan 2020 22:57:58 +0100 Subject: [PATCH] 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 --- src/hcsmakeimage.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hcsmakeimage.c b/src/hcsmakeimage.c index 7baa7b5..2888810 100644 --- a/src/hcsmakeimage.c +++ b/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; } -- 2.30.2