mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-29 13:23:23 +01:00
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]>
This commit is contained in:
1 parent
d927ef5004
commit
657a3efee4
1 file changed
+6
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user