Skip to content

Commit 2020948

Browse files
liujingKernel Patches Daemon
authored andcommitted
bpf: The main function in the file tools/bpf/bpf_dbg.c does not call fclose() to close the opened files at the end, leading to issues such as memory leaks.
Signed-off-by: liujing <[email protected]>
1 parent da4ec66 commit 2020948

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tools/bpf/bpf_dbg.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,11 +1388,18 @@ static int run_shell_loop(FILE *fin, FILE *fout)
13881388
int main(int argc, char **argv)
13891389
{
13901390
FILE *fin = NULL, *fout = NULL;
1391+
int result;
13911392

13921393
if (argc >= 2)
13931394
fin = fopen(argv[1], "r");
13941395
if (argc >= 3)
13951396
fout = fopen(argv[2], "w");
13961397

1397-
return run_shell_loop(fin ? : stdin, fout ? : stdout);
1398+
result = run_shell_loop(fin ? : stdin, fout ? : stdout);
1399+
1400+
if (fin && fin != stdin)
1401+
fclose(fin);
1402+
if (fout && fout != stdout)
1403+
fclose(fout);
1404+
return result;
13981405
}

0 commit comments

Comments
 (0)