[LTP] [PATCH v10 1/3] open01: fix cleanup file descriptor check

Jinseok Kim <[email protected]> Wed, 29 Jul 2026 23:32:01 +0900
Newsgroups it.linux.lists.ltp
Message-ID <[email protected]>
Initialize fd to -1 and check it against -1 in cleanup().

File descriptor 0 is valid, so checking fd > 0 may skip closing an
successfully opened file.

Signed-off-by: Jinseok Kim <[email protected]>
---
 testcases/kernel/syscalls/open/open01.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c
index 1cefb4790..f1a3720aa 100644
--- a/testcases/kernel/syscalls/open/open01.c
+++ b/testcases/kernel/syscalls/open/open01.c
@@ -24,7 +24,7 @@
 #define TEST_FILE	"testfile"
 #define TEST_DIR	"testdir"

-static int fd;
+static int fd = -1;

 static struct tcase {
 	char *filename;
@@ -67,7 +67,7 @@ static void setup(void)

 static void cleanup(void)
 {
-	if (fd > 0)
+	if (fd != -1)
 		SAFE_CLOSE(fd);
 }

--
2.43.0

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp