提交 5e5fd36c 编写于 作者: C Colin Ian King 提交者: Len Brown

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: eae97e05 ("tools/power turbostat: Support thermal throttle count print")
Signed-off-by: NColin Ian King <colin.i.king@gmail.com>
Acked-by: NChen Yu <yu.c.chen@intel.com>
Reviewed-by: NTom Rix <trix@redhat.com>
Signed-off-by: NLen Brown <len.brown@intel.com>
上级 e13da9a1
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册