* [PATCH] tools/power turbostat: close file after use
@ 2022-04-30 14:15 Tom Rix
2022-04-30 14:19 ` Chen Yu
0 siblings, 1 reply; 3+ messages in thread
From: Tom Rix @ 2022-04-30 14:15 UTC (permalink / raw)
To: lenb, yu.c.chen; +Cc: linux-pm, linux-kernel, Tom Rix
The cppcheck reports this issue
turbostat.c:2039]: (error) Resource leak: fp
When the fscanf fails an error is returned without closing fp.
Move the fclose so even if the fscanf fails, the file will be closed.
Fixes: eae97e053fe3 ("tools/power turbostat: Support thermal throttle count print")
Signed-off-by: Tom Rix <trix@redhat.com>
---
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.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tools/power turbostat: close file after use
2022-04-30 14:15 [PATCH] tools/power turbostat: close file after use Tom Rix
@ 2022-04-30 14:19 ` Chen Yu
2022-04-30 14:49 ` Tom Rix
0 siblings, 1 reply; 3+ messages in thread
From: Chen Yu @ 2022-04-30 14:19 UTC (permalink / raw)
To: Tom Rix; +Cc: lenb, linux-pm, linux-kernel
On Sat, Apr 30, 2022 at 10:15:57AM -0400, Tom Rix wrote:
> The cppcheck reports this issue
> turbostat.c:2039]: (error) Resource leak: fp
>
> When the fscanf fails an error is returned without closing fp.
> Move the fclose so even if the fscanf fails, the file will be closed.
>
> Fixes: eae97e053fe3 ("tools/power turbostat: Support thermal throttle count print")
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
> 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;
> --
Thank you Tom, and Colin has proposed a fix here:
https://lore.kernel.org/lkml/20220426131607.1520483-1-colin.i.king@gmail.com/
thanks,
Chenyu
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tools/power turbostat: close file after use
2022-04-30 14:19 ` Chen Yu
@ 2022-04-30 14:49 ` Tom Rix
0 siblings, 0 replies; 3+ messages in thread
From: Tom Rix @ 2022-04-30 14:49 UTC (permalink / raw)
To: Chen Yu; +Cc: lenb, linux-pm, linux-kernel
On 4/30/22 7:19 AM, Chen Yu wrote:
> On Sat, Apr 30, 2022 at 10:15:57AM -0400, Tom Rix wrote:
>> The cppcheck reports this issue
>> turbostat.c:2039]: (error) Resource leak: fp
>>
>> When the fscanf fails an error is returned without closing fp.
>> Move the fclose so even if the fscanf fails, the file will be closed.
>>
>> Fixes: eae97e053fe3 ("tools/power turbostat: Support thermal throttle count print")
>> Signed-off-by: Tom Rix <trix@redhat.com>
>> ---
>> 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;
>> --
> Thank you Tom, and Colin has proposed a fix here:
> https://lore.kernel.org/lkml/20220426131607.1520483-1-colin.i.king@gmail.com/
Obviously I approve of Colin's fix :)
If it is not too much trouble, please add
Reviewed-by: Tom Rix <trix@redhat.com>
If it is already on its way to linux-next, don't worry about it.
Thanks,
Tom
>
> thanks,
> Chenyu
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-30 14:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-30 14:15 [PATCH] tools/power turbostat: close file after use Tom Rix
2022-04-30 14:19 ` Chen Yu
2022-04-30 14:49 ` Tom Rix
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).