]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix CLI memory leak (issue #5035)
authorRussell Bryant <russell@russellbryant.com>
Sat, 24 Sep 2005 21:19:42 +0000 (21:19 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 24 Sep 2005 21:19:42 +0000 (21:19 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@6636 65c4cc65-6c06-0410-ace0-fbb531ad65f3

cli.c

diff --git a/cli.c b/cli.c
index d6100b84aa8027dbecb7e8002d4e2eab44b629a1..11edf1faf1c41c1bda8a1a05ce0e7956b4652762 100755 (executable)
--- 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;
 }