Skip to content

Commit 8c6d871

Browse files
ytcoodeNobody
authored and
Nobody
committed
selftests/bpf: Fix file descriptor leak in load_kallsyms()
Currently, if sym_cnt > 0, it just returns and does not close file, fix it. Signed-off-by: Yuntao Wang <[email protected]>
1 parent 09e1ab5 commit 8c6d871

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/testing/selftests/bpf/trace_helpers.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,23 @@ static int ksym_cmp(const void *p1, const void *p2)
2525

2626
int load_kallsyms(void)
2727
{
28-
FILE *f = fopen("/proc/kallsyms", "r");
28+
FILE *f;
2929
char func[256], buf[256];
3030
char symbol;
3131
void *addr;
3232
int i = 0;
3333

34-
if (!f)
35-
return -ENOENT;
36-
3734
/*
3835
* This is called/used from multiplace places,
3936
* load symbols just once.
4037
*/
4138
if (sym_cnt)
4239
return 0;
4340

41+
f = fopen("/proc/kallsyms", "r");
42+
if (!f)
43+
return -ENOENT;
44+
4445
while (fgets(buf, sizeof(buf), f)) {
4546
if (sscanf(buf, "%p %c %s", &addr, &symbol, func) != 3)
4647
break;

0 commit comments

Comments
 (0)