diff --git a/asterisk.c b/asterisk.c
index 54c9405fbfa4faac040a0a94026b20c4a12026e9..11363c85142d90f860b2791fc9adf3b234d76f1e 100644
--- a/asterisk.c
+++ b/asterisk.c
@@ -1602,12 +1602,13 @@ static char *cli_complete(EditLine *el, int ch)
 			free(mbuf);
 		} else
 			matches = (char **) NULL;
-
-
 	} else {
-
-		nummatches = ast_cli_generatornummatches((char *)lf->buffer,ptr);
+		char **p;
+		int count = 0;
 		matches = ast_cli_completion_matches((char *)lf->buffer,ptr);
+		for (p = matches; p && *p; p++)
+			count++;
+		nummatches = count - 1; /* XXX apparently there is one dup ? */
 	}
 
 	if (matches) {
@@ -1641,7 +1642,7 @@ static char *cli_complete(EditLine *el, int ch)
 				retval = CC_REFRESH;
 			}
 		}
-	free(matches);
+		free(matches);
 	}
 
 	return (char *)(long)retval;