summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-07-27 21:16:45 -0700
committerJunio C Hamano <gitster@pobox.com>2012-07-27 21:16:45 -0700
commit3b0553c3fcb07925ae8f6d6f6f0917737b606cdf (patch)
tree8ede05d550e96303ba44388533b4f6bd2d2a7674
parenta64fe6c1d5949492857e1a5ad14d60175dd484fa (diff)
parent6a17f583f4db98a867d84ca95bbbc4de3cd0feaa (diff)
downloadgit-3b0553c3fcb07925ae8f6d6f6f0917737b606cdf.tar.gz
Merge branch 'jk/help-plug-memleak'
Plug a few trivial memory leaks. * jk/help-plug-memleak: help.c::exclude_cmds(): plug a leak help.c::uniq: plug a leak
-rw-r--r--help.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/help.c b/help.c
index 662349dd56..2a42ec6d1f 100644
--- a/help.c
+++ b/help.c
@@ -44,9 +44,12 @@ static void uniq(struct cmdnames *cmds)
if (!cmds->cnt)
return;
- for (i = j = 1; i < cmds->cnt; i++)
- if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name))
+ for (i = j = 1; i < cmds->cnt; i++) {
+ if (!strcmp(cmds->names[i]->name, cmds->names[j-1]->name))
+ free(cmds->names[i]);
+ else
cmds->names[j++] = cmds->names[i];
+ }
cmds->cnt = j;
}
@@ -61,9 +64,10 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name);
if (cmp < 0)
cmds->names[cj++] = cmds->names[ci++];
- else if (cmp == 0)
- ci++, ei++;
- else if (cmp > 0)
+ else if (cmp == 0) {
+ ei++;
+ free(cmds->names[ci++]);
+ } else if (cmp > 0)
ei++;
}