aboutsummaryrefslogtreecommitdiffstats
path: root/main/cli.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-09 00:44:14 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-09 00:44:14 +0000
commitedc5071cfaab9216cbde2e69eedcf31bb873875b (patch)
treee54a31795064f46df8007fbf92ca90550c224ff2 /main/cli.c
parent86b276998c3325d317fb6267de28bb37ac5e5ea4 (diff)
Allow filename completion on zero-length modules, remove a memory leak, remove
a file descriptor leak, and make filename completion thread-safe. Patched and tested by tilghman. (Closes issue #11681) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@97350 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/cli.c')
-rw-r--r--main/cli.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/main/cli.c b/main/cli.c
index 83e5c71cf..8b5087883 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -1248,7 +1248,7 @@ static char *complete_mod_4(const char *line, const char *word, int pos, int sta
static char *complete_fn_2(const char *line, const char *word, int pos, int state)
{
- char *c;
+ char *c, *d;
char filename[256];
if (pos != 1)
@@ -1259,17 +1259,20 @@ static char *complete_fn_2(const char *line, const char *word, int pos, int stat
else
snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word);
- c = filename_completion_function(filename, state);
+ c = d = filename_completion_function(filename, state);
if (c && word[0] != '/')
c += (strlen(ast_config_AST_MODULE_DIR) + 1);
+ if (c)
+ c = strdup(c);
+ free(d);
- return c ? strdup(c) : c;
+ return c;
}
static char *complete_fn_3(const char *line, const char *word, int pos, int state)
{
- char *c;
+ char *c, *d;
char filename[256];
if (pos != 2)
@@ -1280,12 +1283,15 @@ static char *complete_fn_3(const char *line, const char *word, int pos, int stat
else
snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word);
- c = filename_completion_function(filename, state);
+ c = d = filename_completion_function(filename, state);
if (c && word[0] != '/')
c += (strlen(ast_config_AST_MODULE_DIR) + 1);
+ if (c)
+ c = strdup(c);
+ free(d);
- return c ? strdup(c) : c;
+ return c;
}
static int group_show_channels(int fd, int argc, char *argv[])