From c06e9c400f27debdddf9f474569144531fc39a47 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Thu, 28 Nov 2024 10:51:06 +0900 Subject: [PATCH] Fix a possible leak of a file descriptor When mmap fails for any reason, the fd must be closed. Coverity Scan found this issue. --- src/util/pm_string.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/pm_string.c b/src/util/pm_string.c index 7e56dec9f7..75422fbdf2 100644 --- a/src/util/pm_string.c +++ b/src/util/pm_string.c @@ -189,6 +189,7 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) { source = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); if (source == MAP_FAILED) { + close(fd); return PM_STRING_INIT_ERROR_GENERIC; }