[PATCH] selftests/acct/acct_syscall: Fix file descriptor leak

From: liuye
Date: Mon Jan 13 2025 - 22:35:16 EST


Exception branch returns without closing fp.
Signed-off-by: liuye <liuye@xxxxxxxxxx>
---
tools/testing/selftests/acct/acct_syscall.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/acct/acct_syscall.c b/tools/testing/selftests/acct/acct_syscall.c
index e44e8fe1f4a3..a8a4f8fc9ef9 100644
--- a/tools/testing/selftests/acct/acct_syscall.c
+++ b/tools/testing/selftests/acct/acct_syscall.c
@@ -54,6 +54,7 @@ int main(void)
if (child_pid < 0) {
ksft_test_result_error("Creating a child process to log failed\n");
acct(NULL);
+ fclose(fp);
return 1;
} else if (child_pid > 0) {
wait(NULL);
@@ -65,6 +66,7 @@ int main(void)
if (sz <= 0) {
ksft_test_result_fail("Terminated child process not logged\n");
ksft_exit_fail();
+ fclose(fp);
return 1;
}

@@ -73,6 +75,6 @@ int main(void)
ksft_exit_pass();
return 0;
}
-
+ fclose(fp);
return 1;
}
--
2.25.1