Skip to content

Commit

Permalink
Merge branch 'jk/help-plug-memleak'
Browse files Browse the repository at this point in the history
Plug a few trivial memory leaks.

* jk/help-plug-memleak:
  help.c::exclude_cmds(): plug a leak
  help.c::uniq: plug a leak
  • Loading branch information
Junio C Hamano committed Jul 28, 2012
2 parents a64fe6c + 6a17f58 commit 3b0553c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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++;
}

Expand Down

0 comments on commit 3b0553c

Please sign in to comment.