[LTP] [PATCH] hugemmap/hugemmap05.c: fix warnings in cleanup()

Xiao Yang yangx.jy@cn.fujitsu.com
Thu Aug 31 04:59:39 CEST 2017


1) We only destroy the shared memory segment if it was still created.
2) We only close and delete the test file if it was still created and opened.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
index 90389dd..c73a975 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
@@ -178,9 +178,10 @@ static void test_overcommit(void)
 
 static void cleanup(void)
 {
-	if (opt_shmid) {
+	if (opt_shmid && shmid != -1)
 		SAFE_SHMCTL(shmid, IPC_RMID, NULL);
-	} else {
+
+	if (!opt_shmid && fd != -1) {
 		SAFE_CLOSE(fd);
 		SAFE_UNLINK(TEST_FILE);
 	}
-- 
1.8.3.1





More information about the ltp mailing list