All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/3] memcg/memcontrol02: fix fd leak in cleanup path
@ 2026-08-18 12:14 Disha Goel
  2026-08-18 12:14 ` [LTP] [PATCH v2 2/3] memcg/memcontrol03: fix typos, redundant define and format specifiers Disha Goel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Disha Goel @ 2026-08-18 12:14 UTC (permalink / raw)
  To: ltp; +Cc: Disha Goel

Initialize fd to -1 to distinguish an unopened descriptor, and add
a cleanup guard so SAFE_CLOSE is only called when fd was actually
opened. Without this, cleanup would call close(-1) causing TBROK
when the anon test variant (n=0) runs and never opens fd.

Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
---
v1 -> v2:
- Fix commit message: clarify that fd=0 would close stdin (not silently
  skip), and that the guard is added by this patch not pre-existing
- Use 'fd != -1' instead of 'fd > -1' per LTP convention

 testcases/kernel/controllers/memcg/memcontrol02.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/controllers/memcg/memcontrol02.c b/testcases/kernel/controllers/memcg/memcontrol02.c
index 0b79403c9..52096f697 100644
--- a/testcases/kernel/controllers/memcg/memcontrol02.c
+++ b/testcases/kernel/controllers/memcg/memcontrol02.c
@@ -29,7 +29,7 @@
 
 static size_t page_size;
 static struct tst_cg_group *cg_child;
-static int fd;
+static int fd = -1;
 static int file_to_all_error = 10;
 
 static void alloc_anon_50M_check(void)
@@ -128,6 +128,8 @@ static void cleanup(void)
 {
 	if (cg_child)
 		cg_child = tst_cg_group_rm(cg_child);
+	if (fd != -1)
+		SAFE_CLOSE(fd);
 }
 
 static struct tst_test test = {
-- 
2.45.1


-- 
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-08-18 12:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 12:14 [LTP] [PATCH v2 1/3] memcg/memcontrol02: fix fd leak in cleanup path Disha Goel
2026-08-18 12:14 ` [LTP] [PATCH v2 2/3] memcg/memcontrol03: fix typos, redundant define and format specifiers Disha Goel
2026-08-18 12:14 ` [LTP] [PATCH v2 3/3] memcg/memcontrol04: " Disha Goel
2026-08-18 12:45 ` [LTP] memcg/memcontrol02: fix fd leak in cleanup path linuxtestproject.agent

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.