diff --git a/cli.c b/cli.c index d6100b84aa..11edf1faf1 100755 --- a/cli.c +++ b/cli.c @@ -1004,14 +1004,15 @@ int ast_cli_generatornummatches(char *text, char *word) int matches = 0, i = 0; char *buf = NULL, *oldbuf = NULL; - while ( (buf = ast_cli_generator(text, word, i)) ) { - if (++i > 1 && strcmp(buf,oldbuf) == 0) { - continue; - } + while ( (buf = ast_cli_generator(text, word, i++)) ) { + if (!oldbuf || strcmp(buf,oldbuf)) + matches++; + if (oldbuf) + free(oldbuf); oldbuf = buf; - matches++; } - + if (oldbuf) + free(oldbuf); return matches; }