diff options
author | Andrea Dalla Costa <andrea@dallacosta.me> | 2020-01-11 23:10:51 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-01-14 17:48:50 +0100 |
commit | 8e3b3152e5402b574ff66b149cfdc6e42d61db54 (patch) | |
tree | 73e4fc30a7af30c728f8894cade372d74286035e /tools/firmware-utils/src/mkchkimg.c | |
parent | 0ae0f48cec08e4698e678f5e145533209491e855 (diff) | |
download | upstream-8e3b3152e5402b574ff66b149cfdc6e42d61db54.tar.gz upstream-8e3b3152e5402b574ff66b149cfdc6e42d61db54.tar.bz2 upstream-8e3b3152e5402b574ff66b149cfdc6e42d61db54.zip |
firmware-utils/mkchkimg: fix possible resource leaks
Add missing `fclose` calls for file pointers `kern_fp`, `fs_fp`
and `out_fp`.
Not closing files could lead to resource leaks.
Signed-off-by: Andrea Dalla Costa <andrea@dallacosta.me>
Diffstat (limited to 'tools/firmware-utils/src/mkchkimg.c')
-rw-r--r-- | tools/firmware-utils/src/mkchkimg.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/firmware-utils/src/mkchkimg.c b/tools/firmware-utils/src/mkchkimg.c index 0fe01f0707..5f2823f154 100644 --- a/tools/firmware-utils/src/mkchkimg.c +++ b/tools/firmware-utils/src/mkchkimg.c @@ -231,6 +231,7 @@ main (int argc, char * argv[]) if (fs_file) { fs_fp = fopen (fs_file, "r"); if (!fs_fp) { + fclose(kern_fp); fatal_error (errno, "Cannot open %s", fs_file); } } @@ -238,6 +239,10 @@ main (int argc, char * argv[]) /* Open the output file */ out_fp = fopen (output_file, "w+"); if (!out_fp) { + fclose(kern_fp); + if (fs_fp) { + fclose(fs_fp); + } fatal_error (errno, "Cannot open %s", output_file); } @@ -285,6 +290,7 @@ main (int argc, char * argv[]) netgear_checksum_add (&chk_part, (unsigned char *)buf, len); netgear_checksum_add (&chk_whole, (unsigned char *)buf, len); } + fclose(kern_fp); hdr->kernel_chksum = netgear_checksum_fini (&chk_part); message (" Kernel Len: %u", hdr->kernel_len); message ("Kernel Checksum: 0x%08x", hdr->kernel_chksum); @@ -306,6 +312,7 @@ main (int argc, char * argv[]) netgear_checksum_add (&chk_part, (unsigned char *)buf, len); netgear_checksum_add (&chk_whole, (unsigned char *)buf, len); } + fclose(fs_fp); hdr->rootfs_chksum = (netgear_checksum_fini (&chk_part)); message (" Rootfs Len: %u", hdr->rootfs_len); message ("Rootfs Checksum: 0x%08x", hdr->rootfs_chksum); @@ -336,6 +343,7 @@ main (int argc, char * argv[]) } /* Success */ + fclose(out_fp); return EXIT_SUCCESS; } |