projects
/
linux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
042152c
)
selftests/bpf: Fix file descriptor leak in load_kallsyms()
author
Yuntao Wang
<ytcoode@gmail.com>
Tue, 5 Apr 2022 14:57:11 +0000
(22:57 +0800)
committer
Andrii Nakryiko
<andrii@kernel.org>
Tue, 5 Apr 2022 23:49:32 +0000
(16:49 -0700)
Currently, if sym_cnt > 0, it just returns and does not close file, fix it.
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link:
https://lore.kernel.org/bpf/20220405145711.49543-1-ytcoode@gmail.com
tools/testing/selftests/bpf/trace_helpers.c
patch
|
blob
|
history
diff --git
a/tools/testing/selftests/bpf/trace_helpers.c
b/tools/testing/selftests/bpf/trace_helpers.c
index 3d6217e3aff7ac5c6ce8856ca68cc1d7d778ddb7..9c4be2cdb21a021e30497e1b2da9bb9ba1adb64e 100644
(file)
--- 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;