[PATCH] perf pmu: Fix resource leaks in pmu_cpumask()

Hao Zeng posted 1 patch 2 years, 10 months ago
tools/perf/util/pmu.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] perf pmu: Fix resource leaks in pmu_cpumask()
Posted by Hao Zeng 2 years, 10 months ago
The perf_pmu__open_file() and perf_cpu_map__read()
are called to process the file,but the file is not closed,
which may cause a file handle leak.

Signed-off-by: Hao Zeng <zenghao@kylinos.cn>
---
 tools/perf/util/pmu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index c256b29defad..3b4d2f531d83 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -583,6 +583,7 @@ static struct perf_cpu_map *pmu_cpumask(const char *name)
 		if (!file)
 			continue;
 		cpus = perf_cpu_map__read(file);
+		fclose(file);
 		if (cpus)
 			return cpus;
 	}
-- 
2.37.2


No virus found
		Checked by Hillstone Network AntiVirus
Re: [PATCH] perf pmu: Fix resource leaks in pmu_cpumask()
Posted by Ian Rogers 2 years, 10 months ago
On Wed, Apr 12, 2023 at 7:41 PM Hao Zeng <zenghao@kylinos.cn> wrote:
>
> The perf_pmu__open_file() and perf_cpu_map__read()
> are called to process the file,but the file is not closed,
> which may cause a file handle leak.
>
> Signed-off-by: Hao Zeng <zenghao@kylinos.cn>

Thanks, this was already fixed by Namhyung in:
https://lore.kernel.org/all/20230331202949.810326-9-namhyung@kernel.org/
You may want to check for issues like this in Arnaldo's perf-tools-next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=perf-tools-next
These are the changes planned for Linux 6.4.

Thanks,
Ian

> ---
>  tools/perf/util/pmu.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index c256b29defad..3b4d2f531d83 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -583,6 +583,7 @@ static struct perf_cpu_map *pmu_cpumask(const char *name)
>                 if (!file)
>                         continue;
>                 cpus = perf_cpu_map__read(file);
> +               fclose(file);
>                 if (cpus)
>                         return cpus;
>         }
> --
> 2.37.2
>
>
> No virus found
>                 Checked by Hillstone Network AntiVirus