Commit 5e5fd36c authored by Colin Ian King's avatar Colin Ian King Committed by Len Brown
Browse files

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: default avatarColin Ian King <colin.i.king@gmail.com>
Acked-by: default avatarChen Yu <yu.c.chen@intel.com>
Reviewed-by: default avatarTom Rix <trix@redhat.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent e13da9a1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;