[PATCH 1/2] memcg/memcontrol02: fix fd leak in cleanup path
Disha Goel <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> --- 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