Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v10 1/3] open01: fix cleanup file descriptor check
@ 2026-07-29 14:32 Jinseok Kim
  2026-07-29 14:32 ` [LTP] [PATCH v10 2/3] open01: remove O_DIRECTORY case (move to fstat test) Jinseok Kim
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jinseok Kim @ 2026-07-29 14:32 UTC (permalink / raw)
  To: ltp

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 <always.starving0@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-29 16:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-29 14:32 [LTP] [PATCH v10 1/3] open01: fix cleanup file descriptor check Jinseok Kim
2026-07-29 14:32 ` [LTP] [PATCH v10 2/3] open01: remove O_DIRECTORY case (move to fstat test) Jinseok Kim
2026-07-29 14:32 ` [LTP] [PATCH v10 3/3] fstat: add test for multiple file types using fstat Jinseok Kim
2026-07-29 16:27 ` [LTP] open01: fix cleanup file descriptor check linuxtestproject.agent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox