From: Kevin Darbyshire-Bryant Date: Sun, 16 May 2021 10:46:32 +0000 (+0100) Subject: firmware-utils: fix coverity zytrx.c resource leak X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=34e1644ce63d37b726653c051d4a20a75cceb642;p=project%2Ffirmware-utils.git firmware-utils: fix coverity zytrx.c resource leak fix coverity resource leak warning: *len = stat.st_size; mapped = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (close(fd) < 0) CID 1484880: Resource leaks (RESOURCE_LEAK) Variable "mapped" going out of scope leaks the storage it points to. return NULL; return mapped; } Signed-off-by: Kevin Darbyshire-Bryant --- diff --git a/src/zytrx.c b/src/zytrx.c index 302efc6..7167679 100644 --- a/src/zytrx.c +++ b/src/zytrx.c @@ -150,8 +150,10 @@ static void *map_input(const char *name, size_t *len) } *len = stat.st_size; mapped = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (close(fd) < 0) + if (close(fd) < 0) { + (void) munmap(mapped, stat.st_size); return NULL; + } return mapped; }