diff mbox series

[bpf-next,1/5] selftests/bpf: Fix a fd leak in error paths in open_netns

Message ID bc3aa5ec3d9b91076c40f8356aa0ffcc201c2213.1713613543.git.tanggeliang@kylinos.cn
State New
Headers show
Series use network helpers, part 2 | expand

Commit Message

Geliang Tang April 20, 2024, 11:55 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

As Martin mentioned in review comment, there is an existing bug that
orig_netns_fd will be leaked in the later "goto fail;" case after
open("/proc/self/ns/net") in open_netns() in network_helpers.c. This
patch adds "close(token->orig_netns_fd);" before "free(token);" to
fix it.

Fixes: a30338840fa5 ("selftests/bpf: Move open_netns() and close_netns() into network_helpers.c")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/network_helpers.c | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 9d63d2ac13d8..b2f531a6a4c7 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -478,6 +478,7 @@  struct nstoken *open_netns(const char *name)
 
 	return token;
 fail:
+	close(token->orig_netns_fd);
 	free(token);
 	return NULL;
 }