firmware-utils: fix possible memory leak and resource leak
authorAndrea Dalla Costa <andrea@dallacosta.me>
Sat, 11 Jan 2020 21:41:31 +0000 (22:41 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 14 Jan 2020 16:48:50 +0000 (17:48 +0100)
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>
tools/firmware-utils/src/dns313-header.c

index e69e57e7baaaeb78b5d4ae853bb342e8d2a67e42..3c72b09bfb234cf73661e87db7066a085df4527b 100644 (file)
@@ -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);