[LTP] [PATCH] hugemmap10: Treat fd 0 as valid in cleanup
Huaisheng Ye
yehuaisheng@open-hieco.net
Tue Sep 29 13:15:27 CEST 2026
File descriptor 0 is valid when stdin is closed. The check in
per_iteration_cleanup() skips it and leaks the hugetlbfs file.
Initialize both map_fd slots to -1 and close any descriptor other than
-1. Initializing the slots also prevents cleanup from closing an unused
slot, which would otherwise start at zero.
Reported-by: LTP review agent <linuxtestproject.agent@gmail.com>
Signed-off-by: Huaisheng Ye <yehuaisheng@open-hieco.net>
---
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
index bbbdc82ae..0ffd68962 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
@@ -37,7 +37,7 @@ static char *private_noreserve_opt;
#define NR_SLOTS 2
#define SL_SETUP 0
#define SL_TEST 1
-static int map_fd[NR_SLOTS];
+static int map_fd[NR_SLOTS] = { -1, -1 };
static char *map_addr[NR_SLOTS];
static unsigned long map_size[NR_SLOTS];
static unsigned int touched[NR_SLOTS];
@@ -494,7 +494,7 @@ static void per_iteration_cleanup(void)
for (nr = 0; nr < NR_SLOTS; nr++) {
if (map_addr[nr])
SAFE_MUNMAP(map_addr[nr], map_size[nr]);
- if (map_fd[nr] > 0)
+ if (map_fd[nr] != -1)
SAFE_CLOSE(map_fd[nr]);
}
}
--
2.52.0
More information about the ltp
mailing list