[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250922082241.2204-1-liujing@cmss.chinamobile.com>
Date: Mon, 22 Sep 2025 16:22:41 +0800
From: liujing <liujing@...s.chinamobile.com>
To: ast@...nel.org
Cc: daniel@...earbox.net,
andrii@...nel.org,
martin.lau@...ux.dev,
eddyz87@...il.com,
song@...nel.org,
yonghong.song@...ux.dev,
john.fastabend@...il.com,
kpsingh@...nel.org,
sdf@...ichev.me,
haoluo@...gle.com,
jolsa@...nel.org,
bpf@...r.kernel.org,
linux-kernel@...r.kernel.org,
liujing <liujing@...s.chinamobile.com>
Subject: [PATCH] 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 <liujing@...s.chinamobile.com>
---
tools/bpf/bpf_dbg.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/bpf/bpf_dbg.c b/tools/bpf/bpf_dbg.c
index 00e560a17baf..ac834b6d78a8 100644
--- a/tools/bpf/bpf_dbg.c
+++ b/tools/bpf/bpf_dbg.c
@@ -1388,11 +1388,18 @@ static int run_shell_loop(FILE *fin, FILE *fout)
int main(int argc, char **argv)
{
FILE *fin = NULL, *fout = NULL;
+ int result;
if (argc >= 2)
fin = fopen(argv[1], "r");
if (argc >= 3)
fout = fopen(argv[2], "w");
- return run_shell_loop(fin ? : stdin, fout ? : stdout);
+ result = run_shell_loop(fin ? : stdin, fout ? : stdout);
+
+ if (fin && fin != stdin)
+ fclose(fin);
+ if (fout && fout != stdout)
+ fclose(fout);
+ return result;
}
--
2.27.0
Powered by blists - more mailing lists