All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/5] lib subcmd: Avoid memory leak in exclude_cmds
@ 2023-06-11 23:36 Ian Rogers
  2023-06-11 23:36 ` [PATCH v1 2/5] perf help: Ensure clean_cmds is called on all paths Ian Rogers
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Ian Rogers @ 2023-06-11 23:36 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Thomas Gleixner, Darren Hart,
	Davidlohr Bueso, André Almeida, linux-kernel,
	linux-perf-users

exclude_cmds will shorten the cmds names array, before doing so free
the removed entry.

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


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

end of thread, other threads:[~2023-06-12 18:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v1 1/5] lib subcmd: Avoid memory leak in exclude_cmds Arnaldo Carvalho de Melo

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.