[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <YqIkEzCqgygb6F3f@kernel.org>
Date: Thu, 9 Jun 2022 13:47:15 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Kajol Jain <kjain@...ux.ibm.com>,
Andi Kleen <ak@...ux.intel.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Anshuman Khandual <anshuman.khandual@....com>,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
Rob Herring <robh@...nel.org>,
Stephane Eranian <eranian@...gle.com>
Subject: Re: [PATCH 1/4] libperf evsel: Open shouldn't leak fd on failure
Em Wed, Jun 08, 2022 at 03:43:50PM -0700, Ian Rogers escreveu:
> If the perf_event_open fails the fd is opened but the fd is only freed
> by closing (not by delete). Typically when an open fails you don't call
> close and so this results in a memory leak. To avoid this, add a close
> when open fails.
Thanks, applied.
- Arnaldo
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> ---
> tools/lib/perf/evsel.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
> index c1d58673f6ef..952f3520d5c2 100644
> --- a/tools/lib/perf/evsel.c
> +++ b/tools/lib/perf/evsel.c
> @@ -149,23 +149,30 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
> int fd, group_fd, *evsel_fd;
>
> evsel_fd = FD(evsel, idx, thread);
> - if (evsel_fd == NULL)
> - return -EINVAL;
> + if (evsel_fd == NULL) {
> + err = -EINVAL;
> + goto out;
> + }
>
> err = get_group_fd(evsel, idx, thread, &group_fd);
> if (err < 0)
> - return err;
> + goto out;
>
> fd = sys_perf_event_open(&evsel->attr,
> threads->map[thread].pid,
> cpu, group_fd, 0);
>
> - if (fd < 0)
> - return -errno;
> + if (fd < 0) {
> + err = -errno;
> + goto out;
> + }
>
> *evsel_fd = fd;
> }
> }
> +out:
> + if (err)
> + perf_evsel__close(evsel);
>
> return err;
> }
> --
> 2.36.1.255.ge46751e96f-goog
--
- Arnaldo
Powered by blists - more mailing lists