[LTP] [PATCH v10 1/3] open01: fix cleanup file descriptor check
Jinseok Kim
always.starving0@gmail.com
Wed Jul 29 16:32:01 CEST 2026
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
More information about the ltp
mailing list