mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-17 07:18:15 +00:00
Fix some leaks in CLI (thanks James)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@777 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
10
asterisk.c
10
asterisk.c
@@ -686,14 +686,14 @@ static int ast_el_read_char(EditLine *el, char *cp)
|
|||||||
|
|
||||||
static char *cli_prompt(EditLine *el)
|
static char *cli_prompt(EditLine *el)
|
||||||
{
|
{
|
||||||
char prompt[80];
|
static char prompt[80];
|
||||||
|
|
||||||
if (remotehostname)
|
if (remotehostname)
|
||||||
snprintf(prompt, sizeof(prompt), ASTERISK_PROMPT2, remotehostname);
|
snprintf(prompt, sizeof(prompt), ASTERISK_PROMPT2, remotehostname);
|
||||||
else
|
else
|
||||||
snprintf(prompt, sizeof(prompt), ASTERISK_PROMPT);
|
snprintf(prompt, sizeof(prompt), ASTERISK_PROMPT);
|
||||||
|
|
||||||
return strdup(prompt);
|
return(prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **ast_el_strtoarr(char *buf)
|
static char **ast_el_strtoarr(char *buf)
|
||||||
@@ -839,7 +839,7 @@ static char *cli_complete(EditLine *el, int ch)
|
|||||||
|
|
||||||
if (nummatches == 1) {
|
if (nummatches == 1) {
|
||||||
/* Found an exact match */
|
/* Found an exact match */
|
||||||
el_insertstr(el, strdup(" "));
|
el_insertstr(el, " ");
|
||||||
retval = CC_REFRESH;
|
retval = CC_REFRESH;
|
||||||
} else {
|
} else {
|
||||||
/* Must be more than one match */
|
/* Must be more than one match */
|
||||||
@@ -854,11 +854,11 @@ static char *cli_complete(EditLine *el, int ch)
|
|||||||
ast_cli_display_match_list(matches, nummatches, maxlen);
|
ast_cli_display_match_list(matches, nummatches, maxlen);
|
||||||
retval = CC_REDISPLAY;
|
retval = CC_REDISPLAY;
|
||||||
} else {
|
} else {
|
||||||
el_insertstr(el,strdup(" "));
|
el_insertstr(el," ");
|
||||||
retval = CC_REFRESH;
|
retval = CC_REFRESH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char *)retval;
|
return (char *)retval;
|
||||||
|
|||||||
12
cli.c
12
cli.c
@@ -278,7 +278,10 @@ static int handle_commandmatchesarray(int fd, int argc, char *argv[])
|
|||||||
printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
|
printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
|
||||||
#endif
|
#endif
|
||||||
len += sprintf( buf + len, "%s ", matches[x]);
|
len += sprintf( buf + len, "%s ", matches[x]);
|
||||||
|
free(matches[x]);
|
||||||
|
matches[x] = NULL;
|
||||||
}
|
}
|
||||||
|
free(matches);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
printf("array for '%s' %s got '%s'\n", argv[2], argv[3], buf);
|
printf("array for '%s' %s got '%s'\n", argv[2], argv[3], buf);
|
||||||
@@ -765,12 +768,16 @@ normal:
|
|||||||
int ast_cli_generatornummatches(char *text, char *word)
|
int ast_cli_generatornummatches(char *text, char *word)
|
||||||
{
|
{
|
||||||
int matches = 0, i = 0;
|
int matches = 0, i = 0;
|
||||||
char *buf, *oldbuf;
|
char *buf, *oldbuf = NULL;
|
||||||
|
|
||||||
|
|
||||||
while ( (buf = ast_cli_generator(text, word, i)) ) {
|
while ( (buf = ast_cli_generator(text, word, i)) ) {
|
||||||
if (++i > 1 && strcmp(buf,oldbuf) == 0)
|
if (++i > 1 && strcmp(buf,oldbuf) == 0) {
|
||||||
|
free(buf);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
if (oldbuf)
|
||||||
|
free(oldbuf);
|
||||||
oldbuf = buf;
|
oldbuf = buf;
|
||||||
matches++;
|
matches++;
|
||||||
}
|
}
|
||||||
@@ -866,6 +873,7 @@ static char *__ast_cli_generator(char *text, char *word, int state, int lock)
|
|||||||
if (res) {
|
if (res) {
|
||||||
if (lock)
|
if (lock)
|
||||||
ast_pthread_mutex_unlock(&clilock);
|
ast_pthread_mutex_unlock(&clilock);
|
||||||
|
free(dup);
|
||||||
return res ? strdup(res) : NULL;
|
return res ? strdup(res) : NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user