aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <[email protected]>2023-06-11 16:36:06 -0700
committerArnaldo Carvalho de Melo <[email protected]>2023-06-12 18:18:13 -0300
commit657a3efee43a29d13c4f30e4c8f6a178fd2bf14a (patch)
tree25b2143466ed0db54a661f0b4234a32b27ef9f7f
parentd927ef5004ef79e7fa6e85ff1f62f19fd4051988 (diff)
lib subcmd: Avoid memory leak in exclude_cmds
exclude_cmds will shorten the cmds names array, before doing so free the removed entry. Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: AndrĂ© Almeida <[email protected]> Cc: Darren Hart <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r--tools/lib/subcmd/help.c8
1 files 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;
}