[LTP] [PATCH] hugemmap05: close the temporary file before cleaning up

Sheng Yong shengyong1@huawei.com
Wed Nov 25 13:20:42 CET 2015


If mmap() fails, we cannot umount and clean the temporary directory since
a file is still open in it. So close the file before doing cleanup.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
index 8dac97a..b68c981 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
@@ -162,8 +162,10 @@ static void overcommit(void)
 			tst_brkm(TBROK | TERRNO, cleanup, "open");
 		addr = mmap(ADDR, (long)(length / 2 * hugepagesize), PROTECTION,
 			    FLAGS, fd, 0);
-		if (addr == MAP_FAILED)
+		if (addr == MAP_FAILED) {
+			close(fd);
 			tst_brkm(TBROK | TERRNO, cleanup, "mmap");
+		}
 	}
 
 	if (opt_sysfs) {
-- 
1.8.3.4



More information about the Ltp mailing list