aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils
diff options
context:
space:
mode:
authorAndrea Dalla Costa <andrea@dallacosta.me>2020-01-11 22:41:31 +0100
committerJo-Philipp Wich <jo@mein.io>2020-01-14 17:48:50 +0100
commit0ae0f48cec08e4698e678f5e145533209491e855 (patch)
tree6f06794e3dcadf3b13b6d6eff38946939167fe8e /tools/firmware-utils
parent402b362db447c8163b4069537753b1ede3533d18 (diff)
downloadupstream-0ae0f48cec08e4698e678f5e145533209491e855.tar.gz
upstream-0ae0f48cec08e4698e678f5e145533209491e855.tar.bz2
upstream-0ae0f48cec08e4698e678f5e145533209491e855.zip
firmware-utils: fix possible memory leak and resource leak
Add missing calls to `free` for variable `buffer`. This could lead to a memory leak. Add missing call to `close` for file pointer `fdin`. This could lead to a resource leak. Signed-off-by: Andrea Dalla Costa <andrea@dallacosta.me>
Diffstat (limited to 'tools/firmware-utils')
-rw-r--r--tools/firmware-utils/src/dns313-header.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/firmware-utils/src/dns313-header.c b/tools/firmware-utils/src/dns313-header.c
index e69e57e7ba..3c72b09bfb 100644
--- a/tools/firmware-utils/src/dns313-header.c
+++ b/tools/firmware-utils/src/dns313-header.c
@@ -168,11 +168,14 @@ int main(int argc, char **argv)
fdin = open(pathin, O_RDONLY);
if (!fdin) {
printf("ERROR: could not open input file\n");
+ free(buffer);
return 0;
}
bytes = read(fdin, buffer + HEADER_SIZE, filesize);
if (bytes < filesize) {
printf("ERROR: could not read entire file\n");
+ free(buffer);
+ close(fdin);
return 0;
}
close(fdin);