[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241128024717.2719-1-liujing@cmss.chinamobile.com>
Date: Thu, 28 Nov 2024 10:47:17 +0800
From: liujing <liujing@...s.chinamobile.com>
To: ast@...nel.org,
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
Cc: bpf@...r.kernel.org,
linux-kernel@...r.kernel.org,
liujing <liujing@...s.chinamobile.com>
Subject: [PATCH] bpf: Optimize resource leakage problems
If fopen executes successfully in the main function, it does
not close the open file stream before the end of the function.
Signed-off-by: liujing <liujing@...s.chinamobile.com>
diff --git a/tools/bpf/bpf_dbg.c b/tools/bpf/bpf_dbg.c
index 00e560a17baf..2445dfb4fc46 100644
--- a/tools/bpf/bpf_dbg.c
+++ b/tools/bpf/bpf_dbg.c
@@ -1388,11 +1388,17 @@ 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)
+ fclose(fin);
+
+ if (fout)
+ fclose(fout);
+ return result;
}
--
2.27.0
Powered by blists - more mailing lists