From: Andrea Dalla Costa Date: Sat, 11 Jan 2020 21:41:31 +0000 (+0100) Subject: firmware-utils: fix possible memory leak and resource leak X-Git-Tag: v21.02.0-rc1~4056 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0ae0f48cec08e4698e678f5e145533209491e855;p=openwrt%2Fstaging%2Fchunkeey.git 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 --- 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);