diff mbox series

[bpf-next] selftests/bpf: fix two memory leaks in prog_tests

Message ID 20220428225744.1961643-1-mykolal@fb.com (mailing list archive)
State Accepted
Commit 20b87e7c29dffcfa3f96f2e99daec84fd46cabdb
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: fix two memory leaks in prog_tests | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 8 maintainers not CCed: songliubraving@fb.com shuah@kernel.org netdev@vger.kernel.org kafai@fb.com linux-kselftest@vger.kernel.org yhs@fb.com john.fastabend@gmail.com kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 64 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest + selftests
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on z15 + selftests

Commit Message

Mykola Lysenko April 28, 2022, 10:57 p.m. UTC
Fix log_fp memory leak in dispatch_thread_read_log.
Remove obsolete log_fp clean-up code in dispatch_thread.

Also, release memory of subtest_selector. This can be
reproduced with -n 2/1 parameters.

Signed-off-by: Mykola Lysenko <mykolal@fb.com>
---
 tools/testing/selftests/bpf/test_progs.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org April 29, 2022, 5 a.m. UTC | #1
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu, 28 Apr 2022 15:57:44 -0700 you wrote:
> Fix log_fp memory leak in dispatch_thread_read_log.
> Remove obsolete log_fp clean-up code in dispatch_thread.
> 
> Also, release memory of subtest_selector. This can be
> reproduced with -n 2/1 parameters.
> 
> Signed-off-by: Mykola Lysenko <mykolal@fb.com>
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: fix two memory leaks in prog_tests
    https://git.kernel.org/bpf/bpf-next/c/20b87e7c29df

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 22fe283710fa..a07da648af3b 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -77,10 +77,12 @@  static void stdio_restore_cleanup(void)
 
 	if (env.subtest_state) {
 		fclose(env.subtest_state->stdout);
+		env.subtest_state->stdout = NULL;
 		stdout = env.test_state->stdout;
 		stderr = env.test_state->stdout;
 	} else {
 		fclose(env.test_state->stdout);
+		env.test_state->stdout = NULL;
 	}
 #endif
 }
@@ -1077,6 +1079,7 @@  static int read_prog_test_msg(int sock_fd, struct msg *msg, enum msg_type type)
 static int dispatch_thread_read_log(int sock_fd, char **log_buf, size_t *log_cnt)
 {
 	FILE *log_fp = NULL;
+	int result = 0;
 
 	log_fp = open_memstream(log_buf, log_cnt);
 	if (!log_fp)
@@ -1085,16 +1088,20 @@  static int dispatch_thread_read_log(int sock_fd, char **log_buf, size_t *log_cnt
 	while (true) {
 		struct msg msg;
 
-		if (read_prog_test_msg(sock_fd, &msg, MSG_TEST_LOG))
-			return 1;
+		if (read_prog_test_msg(sock_fd, &msg, MSG_TEST_LOG)) {
+			result = 1;
+			goto out;
+		}
 
 		fprintf(log_fp, "%s", msg.test_log.log_buf);
 		if (msg.test_log.is_last)
 			break;
 	}
+
+out:
 	fclose(log_fp);
 	log_fp = NULL;
-	return 0;
+	return result;
 }
 
 static int dispatch_thread_send_subtests(int sock_fd, struct test_state *state)
@@ -1132,7 +1139,6 @@  static void *dispatch_thread(void *ctx)
 {
 	struct dispatch_data *data = ctx;
 	int sock_fd;
-	FILE *log_fp = NULL;
 
 	sock_fd = data->sock_fd;
 
@@ -1214,8 +1220,6 @@  static void *dispatch_thread(void *ctx)
 	if (env.debug)
 		fprintf(stderr, "[%d]: Protocol/IO error: %s.\n", data->worker_id, strerror(errno));
 
-	if (log_fp)
-		fclose(log_fp);
 done:
 	{
 		struct msg msg_exit;
@@ -1685,6 +1689,7 @@  int main(int argc, char **argv)
 		unload_bpf_testmod();
 
 	free_test_selector(&env.test_selector);
+	free_test_selector(&env.subtest_selector);
 	free_test_states();
 
 	if (env.succ_cnt + env.fail_cnt + env.skip_cnt == 0)