tools/power turbostat: Fix file pointer leak
Subsystems (2)
PATCH 1/1 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 <[email protected]>
--- tools/power/x86/turbostat/turbostat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.c +1 -1
@@ -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 ;
Signature · 1 line
2.35.1
Quoted 17 lines · Colin Ian King
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 <[email protected]>--- tools/power/x86/turbostat/turbostat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/power/x86/turbostat/turbostat.c +0
-0
tools/power/x86/turbostat/turbostat.c int get_core_throt_cnt(int cpu, unsigned long long *cnt) · line 2043
Quoted 10 lines
tools/power/x86/turbostat/turbostat.c +1
-1@@ -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 ;
Acked-by Chen Yu <[email protected]>
Thanks for fixing it.
Chenyu