From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: "Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Mark Rutland" <mark.rutland@arm.com>,
"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
"Jiri Olsa" <jolsa@kernel.org>,
"Namhyung Kim" <namhyung@kernel.org>,
"Adrian Hunter" <adrian.hunter@intel.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Darren Hart" <dvhart@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"André Almeida" <andrealmeid@igalia.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1 1/5] lib subcmd: Avoid memory leak in exclude_cmds
Date: Mon, 12 Jun 2023 15:52:28 -0300 [thread overview]
Message-ID: <ZIdpbMGu/V+VO8c+@kernel.org> (raw)
In-Reply-To: <20230611233610.953456-1-irogers@google.com>
Em Sun, Jun 11, 2023 at 04:36:06PM -0700, Ian Rogers escreveu:
> exclude_cmds will shorten the cmds names array, before doing so free
> the removed entry.
Thanks, applied.
- Arnaldo
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/lib/subcmd/help.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
> index bf02d62a3b2b..a66fb1a1a312 100644
> --- a/tools/lib/subcmd/help.c
> +++ b/tools/lib/subcmd/help.c
> @@ -66,6 +66,7 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
> while (ci < cmds->cnt && ei < excludes->cnt) {
> cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name);
> if (cmp < 0) {
> + zfree(&cmds->names[cj]);
> cmds->names[cj++] = cmds->names[ci++];
> } else if (cmp == 0) {
> ci++;
> @@ -75,9 +76,12 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
> }
> }
>
> - while (ci < cmds->cnt)
> + while (ci < cmds->cnt) {
> + zfree(&cmds->names[cj]);
> cmds->names[cj++] = cmds->names[ci++];
> -
> + }
> + for (ci = cj; ci < cmds->cnt; ci++)
> + zfree(&cmds->names[ci]);
> cmds->cnt = cj;
> }
>
> --
> 2.41.0.162.gfafddb0af9-goog
>
--
- Arnaldo
prev parent reply other threads:[~2023-06-12 18:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-11 23:36 [PATCH v1 1/5] lib subcmd: Avoid memory leak in exclude_cmds Ian Rogers
2023-06-11 23:36 ` [PATCH v1 2/5] perf help: Ensure clean_cmds is called on all paths Ian Rogers
2023-06-11 23:36 ` [PATCH v1 3/5] perf bench epoll: Fix missing frees/puts Ian Rogers
2023-06-11 23:36 ` [PATCH v1 4/5] perf bench futex: Avoid memory leaks from pthread_attr Ian Rogers
2023-06-11 23:36 ` [PATCH v1 5/5] perf bench sched messaging: Free contexts on exit Ian Rogers
2023-06-12 18:52 ` Arnaldo Carvalho de Melo [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=ZIdpbMGu/V+VO8c+@kernel.org \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrealmeid@igalia.com \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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).