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 <ldir@darbyshire-bryant.me.uk>
(cherry picked from commit baf2a50ef3)
This commit is contained in:
Kevin Darbyshire-Bryant 2021-05-16 11:46:32 +01:00 committed by Petr Štetiar
parent dd6f02a3f4
commit 27f4559281
1 changed files with 3 additions and 1 deletions

View File

@ -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;
}