[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220815180451.559713255@linuxfoundation.org>
Date: Mon, 15 Aug 2022 19:54:14 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: linux-kernel@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
stable@...r.kernel.org, Colin Ian King <colin.i.king@...il.com>,
Chen Yu <yu.c.chen@...el.com>, Tom Rix <trix@...hat.com>,
Len Brown <len.brown@...el.com>,
Sasha Levin <sashal@...nel.org>
Subject: [PATCH 5.19 0298/1157] tools/power turbostat: Fix file pointer leak
From: Colin Ian King <colin.i.king@...il.com>
[ Upstream commit 5e5fd36c58d6c820f7292ee492c3731c9a104a41 ]
Currently if a fscanf fails then an early return leaks an open
file pointer. Fix this by fclosing the file before the return.
Detected using static analysis with cppcheck:
tools/power/x86/turbostat/turbostat.c:2039:3: error: Resource leak: fp [resourceLeak]
Fixes: eae97e053fe3 ("tools/power turbostat: Support thermal throttle count print")
Signed-off-by: Colin Ian King <colin.i.king@...il.com>
Acked-by: Chen Yu <yu.c.chen@...el.com>
Reviewed-by: Tom Rix <trix@...hat.com>
Signed-off-by: Len Brown <len.brown@...el.com>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
tools/power/x86/turbostat/turbostat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index ede31a4287a0..2e9a751af260 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2035,9 +2035,9 @@ int get_core_throt_cnt(int cpu, unsigned long long *cnt)
if (!fp)
return -1;
ret = fscanf(fp, "%lld", &tmp);
+ fclose(fp);
if (ret != 1)
return -1;
- fclose(fp);
*cnt = tmp;
return 0;
--
2.35.1
Powered by blists - more mailing lists