Signed-off-by: Tay Ray Chuan <rctay89@xxxxxxxxx> --- help.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/help.c b/help.c index 69d483d..b64056d 100644 --- a/help.c +++ b/help.c @@ -38,14 +38,24 @@ static int cmdname_compare(const void *a_, const void *b_) static void uniq(struct cmdnames *cmds) { - int i, j; + int i, j, c = 0; if (!cmds->cnt) return; for (i = j = 1; i < cmds->cnt; i++) - if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) + if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) { + + /* The i-1 entry was the cth duplicate + * Guarantees c=0 + */ + for (; c >= 1; c--) + free(cmds->names[i - c]); + cmds->names[j++] = cmds->names[i]; + } else { + c++; + } cmds->cnt = j; } -- 1.7.10.1.611.g8a79d96 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html