linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen Yu <yu.c.chen@intel.com>
To: Colin Ian King <colin.i.king@gmail.com>
Cc: Len Brown <lenb@kernel.org>,
	linux-pm@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/power turbostat: Fix file pointer leak
Date: Tue, 26 Apr 2022 21:39:26 +0800	[thread overview]
Message-ID: <20220426133926.GA33188@chenyu5-mobl1> (raw)
In-Reply-To: <20220426131607.1520483-1-colin.i.king@gmail.com>

On Tue, Apr 26, 2022 at 02:16:07PM +0100, Colin Ian King wrote:
> 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 <colin.i.king@gmail.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 e6779f599a8e..db431b31c4df 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;
Acked-by: Chen Yu <yu.c.chen@intel.com>

Thanks for fixing it.


Chenyu

      reply	other threads:[~2022-04-26 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 13:16 [PATCH] tools/power turbostat: Fix file pointer leak Colin Ian King
2022-04-26 13:39 ` Chen Yu [this message]

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=20220426133926.GA33188@chenyu5-mobl1 \
    --to=yu.c.chen@intel.com \
    --cc=colin.i.king@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).