All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ] tools/power x86_energy_perf_policy: Fix file leak in get_pkg_num()
@ 2024-02-14  0:19 Samasth Norway Ananda
  2024-02-22 19:06 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Samasth Norway Ananda @ 2024-02-14  0:19 UTC (permalink / raw)
  To: lenb; +Cc: samasth.norway.ananda, linux-pm

In function get_pkg_num() if fopen_or_die() succeeds it returns a file
pointer to be used. But fclose() is never called before returning from
the function.

Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
---
Found this error through static analysis. This has only been compile
tested.
---
 tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
index 5fd9e594079c..ebda9c366b2b 100644
--- a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
+++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
@@ -1241,6 +1241,7 @@ unsigned int get_pkg_num(int cpu)
 	retval = fscanf(fp, "%d\n", &pkg);
 	if (retval != 1)
 		errx(1, "%s: failed to parse", pathname);
+	fclose(fp);
 	return pkg;
 }
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH ] tools/power x86_energy_perf_policy: Fix file leak in get_pkg_num()
  2024-02-14  0:19 [PATCH ] tools/power x86_energy_perf_policy: Fix file leak in get_pkg_num() Samasth Norway Ananda
@ 2024-02-22 19:06 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2024-02-22 19:06 UTC (permalink / raw)
  To: Samasth Norway Ananda; +Cc: lenb, linux-pm

On Wed, Feb 14, 2024 at 1:20 AM Samasth Norway Ananda
<samasth.norway.ananda@oracle.com> wrote:
>
> In function get_pkg_num() if fopen_or_die() succeeds it returns a file
> pointer to be used. But fclose() is never called before returning from
> the function.
>
> Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
> ---
> Found this error through static analysis. This has only been compile
> tested.
> ---
>  tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
> index 5fd9e594079c..ebda9c366b2b 100644
> --- a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
> +++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
> @@ -1241,6 +1241,7 @@ unsigned int get_pkg_num(int cpu)
>         retval = fscanf(fp, "%d\n", &pkg);
>         if (retval != 1)
>                 errx(1, "%s: failed to parse", pathname);
> +       fclose(fp);
>         return pkg;
>  }
>
> --

Applied as 6.9 material, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-22 19:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14  0:19 [PATCH ] tools/power x86_energy_perf_policy: Fix file leak in get_pkg_num() Samasth Norway Ananda
2024-02-22 19:06 ` Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.