From: Chen Yu <yu.c.chen@intel.com>
To: Tom Rix <trix@redhat.com>
Cc: lenb@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/power turbostat: close file after use
Date: Sat, 30 Apr 2022 22:19:47 +0800 [thread overview]
Message-ID: <20220430141947.GA5101@chenyu5-mobl1> (raw)
In-Reply-To: <20220430141557.1065405-1-trix@redhat.com>
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
next prev parent reply other threads:[~2022-04-30 14:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-30 14:15 [PATCH] tools/power turbostat: close file after use Tom Rix
2022-04-30 14:19 ` Chen Yu [this message]
2022-04-30 14:49 ` Tom Rix
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220430141947.GA5101@chenyu5-mobl1 \
--to=yu.c.chen@intel.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=trix@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox