[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM9d7cgvRO0niWKi8dVnaYU1Y0C2hWCYxdA+Yb1vObDdgK85Kg@mail.gmail.com>
Date: Thu, 9 May 2024 11:24:10 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: zhaimingbing <zhaimingbing@...s.chinamobile.com>,
Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>, Kan Liang <kan.liang@...ux.intel.com>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1] perf lock: Avoid memory leaks from strdup
On Wed, May 8, 2024 at 10:31 PM Ian Rogers <irogers@...gle.com> wrote:
>
> Leak sanitizer complains about the strdup-ed arguments not being freed
> and given cmd_record doesn't modify the given strings, remove the
> strdups.
>
> Original discussion in this patch:
> https://lore.kernel.org/lkml/20240430184156.1824083-1-irogers@google.com/
>
> Suggested-by: Namhyung Kim <namhyung@...nel.org>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
Acked-by: Namhyung Kim <namhyung@...nel.org>
Thanks,
Namhyung
> ---
> tools/perf/builtin-lock.c | 18 ++++--------------
> 1 file changed, 4 insertions(+), 14 deletions(-)
>
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index 230461280e45..7007d26fe654 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -2275,23 +2275,13 @@ static int __cmd_record(int argc, const char **argv)
> return -ENOMEM;
>
> for (i = 0; i < ARRAY_SIZE(record_args); i++)
> - rec_argv[i] = strdup(record_args[i]);
> + rec_argv[i] = record_args[i];
>
> for (j = 0; j < nr_tracepoints; j++) {
> - const char *ev_name;
> -
> - if (has_lock_stat)
> - ev_name = strdup(lock_tracepoints[j].name);
> - else
> - ev_name = strdup(contention_tracepoints[j].name);
> -
> - if (!ev_name) {
> - free(rec_argv);
> - return -ENOMEM;
> - }
> -
> rec_argv[i++] = "-e";
> - rec_argv[i++] = ev_name;
> + rec_argv[i++] = has_lock_stat
> + ? lock_tracepoints[j].name
> + : contention_tracepoints[j].name;
> }
>
> for (j = 0; j < nr_callgraph_args; j++, i++)
> --
> 2.45.0.rc1.225.g2a3ae87e7f-goog
>
Powered by blists - more mailing lists