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

fd is initialized to 0 (a valid file descriptor) so the cleanup()
guard 'if (fd > -1)' would never trigger. Initialize to -1 and
add SAFE_CLOSE to prevent the descriptor leaking when a SAFE_*
macro calls tst_brk() during the pagecache allocation test.

Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
---
 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..75a1e6d51 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-10  9:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 13:05 [LTP] [PATCH 1/2] memcg/memcontrol02: fix fd leak in cleanup path Disha Goel
2026-08-07 13:05 ` [LTP] [PATCH 2/2] memcg/memcontrol03-04: fix typos, redundant define and format specifiers Disha Goel
2026-08-07 14:18 ` [LTP] memcg/memcontrol02: fix fd leak in cleanup path linuxtestproject.agent
2026-08-10  9:41   ` Andrea Cervesato via ltp

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.