* [PATCH bpf-next] selftests/bpf: Fix file descriptor leak in load_kallsyms()
@ 2022-04-05 14:57 Yuntao Wang
2022-04-06 0:00 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Yuntao Wang @ 2022-04-05 14:57 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Shuah Khan, netdev, bpf, linux-kernel, linux-kselftest,
Yuntao Wang
Currently, if sym_cnt > 0, it just returns and does not close file, fix it.
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
tools/testing/selftests/bpf/trace_helpers.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index 3d6217e3aff7..9c4be2cdb21a 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -25,15 +25,12 @@ static int ksym_cmp(const void *p1, const void *p2)
int load_kallsyms(void)
{
- FILE *f = fopen("/proc/kallsyms", "r");
+ FILE *f;
char func[256], buf[256];
char symbol;
void *addr;
int i = 0;
- if (!f)
- return -ENOENT;
-
/*
* This is called/used from multiplace places,
* load symbols just once.
@@ -41,6 +38,10 @@ int load_kallsyms(void)
if (sym_cnt)
return 0;
+ f = fopen("/proc/kallsyms", "r");
+ if (!f)
+ return -ENOENT;
+
while (fgets(buf, sizeof(buf), f)) {
if (sscanf(buf, "%p %c %s", &addr, &symbol, func) != 3)
break;
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Fix file descriptor leak in load_kallsyms()
2022-04-05 14:57 [PATCH bpf-next] selftests/bpf: Fix file descriptor leak in load_kallsyms() Yuntao Wang
@ 2022-04-06 0:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-06 0:00 UTC (permalink / raw)
To: Yuntao Wang
Cc: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
kpsingh, shuah, netdev, bpf, linux-kernel, linux-kselftest
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Tue, 5 Apr 2022 22:57:11 +0800 you wrote:
> Currently, if sym_cnt > 0, it just returns and does not close file, fix it.
>
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
> tools/testing/selftests/bpf/trace_helpers.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
Here is the summary with links:
- [bpf-next] selftests/bpf: Fix file descriptor leak in load_kallsyms()
https://git.kernel.org/bpf/bpf-next/c/2d0df01974ce
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-06 5:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 14:57 [PATCH bpf-next] selftests/bpf: Fix file descriptor leak in load_kallsyms() Yuntao Wang
2022-04-06 0:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).