summaryrefslogtreecommitdiffstats
path: root/tools/power
diff options
context:
space:
mode:
authorColin Ian King <colin.i.king@gmail.com>2022-04-26 15:16:07 +0200
committerLen Brown <len.brown@intel.com>2022-07-28 20:23:25 +0200
commit5e5fd36c58d6c820f7292ee492c3731c9a104a41 (patch)
treea7088b4fa84edd0a004fa549f68f50512d09469c /tools/power
parenttools/power turbostat: replace strncmp with single character compare (diff)
downloadlinux-5e5fd36c58d6c820f7292ee492c3731c9a104a41.tar.xz
linux-5e5fd36c58d6c820f7292ee492c3731c9a104a41.zip
tools/power turbostat: Fix file pointer leak
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@gmail.com> Acked-by: Chen Yu <yu.c.chen@intel.com> Reviewed-by: Tom Rix <trix@redhat.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/x86/turbostat/turbostat.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 4593f8d5b617..c451fafd2e3b 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;