Fix CLI memory leak (bug #5035)
authorMark Spencer <markster@digium.com>
Sat, 24 Sep 2005 15:25:52 +0000 (15:25 +0000)
committerMark Spencer <markster@digium.com>
Sat, 24 Sep 2005 15:25:52 +0000 (15:25 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6635 65c4cc65-6c06-0410-ace0-fbb531ad65f3

cli.c

diff --git a/cli.c b/cli.c
index e6e8d0b..8e22353 100755 (executable)
--- a/cli.c
+++ b/cli.c
@@ -1203,14 +1203,15 @@ int ast_cli_generatornummatches(char *text, char *word)
        int matches = 0, i = 0;
        char *buf = NULL, *oldbuf = NULL;
 
        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;
                oldbuf = buf;
-               matches++;
        }
        }
-
+       if (oldbuf)
+               free(oldbuf);
        return matches;
 }
 
        return matches;
 }