mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 23:08:32 +00:00
Fix misuses of asprintf throughout the code.
This fixes three main issues * Change asprintf() uses to ast_asprintf() so that it pairs properly with ast_free() and no longer causes MALLOC_DEBUG to freak out. * When ast_asprintf() fails, set the pointer NULL if it will be referenced later. * Fix some memory leaks that were spotted while taking care of the first two points. (Closes issue ASTERISK-20135) reported by Richard Mudgett Review: https://reviewboard.asterisk.org/r/2071 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@371590 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -2795,8 +2795,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
|
|||||||
ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
|
ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
|
||||||
what_is_s = "~~s~~";
|
what_is_s = "~~s~~";
|
||||||
}
|
}
|
||||||
if (asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
|
if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
gosub_args = NULL;
|
gosub_args = NULL;
|
||||||
}
|
}
|
||||||
*gosub_argstart = ',';
|
*gosub_argstart = ',';
|
||||||
@@ -2806,8 +2805,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
|
|||||||
ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
|
ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
|
||||||
what_is_s = "~~s~~";
|
what_is_s = "~~s~~";
|
||||||
}
|
}
|
||||||
if (asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
|
if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
gosub_args = NULL;
|
gosub_args = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5012,8 +5012,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
|
|||||||
ast_exists_extension(peer, gosubexec, "~~s~~", 1, S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
|
ast_exists_extension(peer, gosubexec, "~~s~~", 1, S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
|
||||||
what_is_s = "~~s~~";
|
what_is_s = "~~s~~";
|
||||||
}
|
}
|
||||||
if (asprintf(&gosub_args, "%s,%s,1(%s)", gosubexec, what_is_s, gosub_argstart + 1) < 0) {
|
if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", gosubexec, what_is_s, gosub_argstart + 1) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
gosub_args = NULL;
|
gosub_args = NULL;
|
||||||
}
|
}
|
||||||
*gosub_argstart = ',';
|
*gosub_argstart = ',';
|
||||||
@@ -5023,8 +5022,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
|
|||||||
ast_exists_extension(peer, gosubexec, "~~s~~", 1, S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
|
ast_exists_extension(peer, gosubexec, "~~s~~", 1, S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
|
||||||
what_is_s = "~~s~~";
|
what_is_s = "~~s~~";
|
||||||
}
|
}
|
||||||
if (asprintf(&gosub_args, "%s,%s,1", gosubexec, what_is_s) < 0) {
|
if (ast_asprintf(&gosub_args, "%s,%s,1", gosubexec, what_is_s) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
gosub_args = NULL;
|
gosub_args = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -792,13 +792,11 @@ static int handle_gosub(struct ast_channel *chan, AGI *agi, int argc, const char
|
|||||||
* call a Gosub for the CALLEE channel in Dial or Queue.
|
* call a Gosub for the CALLEE channel in Dial or Queue.
|
||||||
*/
|
*/
|
||||||
if (argc == 5) {
|
if (argc == 5) {
|
||||||
if (asprintf(&gosub_args, "%s,%s,%d(%s)", argv[1], argv[2], priority + (chan->pbx ? 1 : 0), argv[4]) < 0) {
|
if (ast_asprintf(&gosub_args, "%s,%s,%d(%s)", argv[1], argv[2], priority + (chan->pbx ? 1 : 0), argv[4]) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
gosub_args = NULL;
|
gosub_args = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (asprintf(&gosub_args, "%s,%s,%d", argv[1], argv[2], priority + (chan->pbx ? 1 : 0)) < 0) {
|
if (ast_asprintf(&gosub_args, "%s,%s,%d", argv[1], argv[2], priority + (chan->pbx ? 1 : 0)) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
gosub_args = NULL;
|
gosub_args = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,11 +360,11 @@ static int execute_and_consume(DBPROCESS *dbproc, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (dbfcmd(dbproc, buffer) == FAIL) {
|
if (dbfcmd(dbproc, buffer) == FAIL) {
|
||||||
free(buffer);
|
ast_free(buffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
ast_free(buffer);
|
||||||
|
|
||||||
if (dbsqlexec(dbproc) == FAIL) {
|
if (dbsqlexec(dbproc) == FAIL) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -14233,8 +14233,8 @@ static char *complete_span_helper(const char *line, const char *word, int pos, i
|
|||||||
|
|
||||||
for (which = span = 0; span < NUM_SPANS; span++) {
|
for (which = span = 0; span < NUM_SPANS; span++) {
|
||||||
if (pris[span].pri.pri && ++which > state) {
|
if (pris[span].pri.pri && ++which > state) {
|
||||||
if (asprintf(&ret, "%d", span + 1) < 0) { /* user indexes start from 1 */
|
if (ast_asprintf(&ret, "%d", span + 1) < 0) { /* user indexes start from 1 */
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
ret = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1391,9 +1391,7 @@ static struct chan_oss_pvt *store_config(struct ast_config *cfg, char *ctg)
|
|||||||
if (o->mixer_cmd) {
|
if (o->mixer_cmd) {
|
||||||
char *cmd;
|
char *cmd;
|
||||||
|
|
||||||
if (asprintf(&cmd, "mixer %s", o->mixer_cmd) < 0) {
|
if (ast_asprintf(&cmd, "mixer %s", o->mixer_cmd) >= 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
} else {
|
|
||||||
ast_log(LOG_WARNING, "running [%s]\n", cmd);
|
ast_log(LOG_WARNING, "running [%s]\n", cmd);
|
||||||
if (system(cmd) < 0) {
|
if (system(cmd) < 0) {
|
||||||
ast_log(LOG_WARNING, "system() failed: %s\n", strerror(errno));
|
ast_log(LOG_WARNING, "system() failed: %s\n", strerror(errno));
|
||||||
|
|||||||
@@ -28085,9 +28085,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
|
|||||||
ast_free_ha(olddirectmediaha);
|
ast_free_ha(olddirectmediaha);
|
||||||
if (!ast_strlen_zero(callback)) { /* build string from peer info */
|
if (!ast_strlen_zero(callback)) { /* build string from peer info */
|
||||||
char *reg_string;
|
char *reg_string;
|
||||||
if (asprintf(®_string, "%s?%s:%s@%s/%s", peer->name, peer->username, !ast_strlen_zero(peer->remotesecret) ? peer->remotesecret : peer->secret, peer->tohost, callback) < 0) {
|
if (ast_asprintf(®_string, "%s?%s:%s@%s/%s", peer->name, peer->username, !ast_strlen_zero(peer->remotesecret) ? peer->remotesecret : peer->secret, peer->tohost, callback) >= 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
} else if (reg_string) {
|
|
||||||
sip_register(reg_string, 0); /* XXX TODO: count in registry_count */
|
sip_register(reg_string, 0); /* XXX TODO: count in registry_count */
|
||||||
ast_free(reg_string);
|
ast_free(reg_string);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -953,12 +953,12 @@ static int init_acf_query(struct ast_config *cfg, char *catg, struct acf_odbc_qu
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((tmp = ast_variable_retrieve(cfg, catg, "prefix")) && !ast_strlen_zero(tmp)) {
|
if ((tmp = ast_variable_retrieve(cfg, catg, "prefix")) && !ast_strlen_zero(tmp)) {
|
||||||
if (asprintf((char **)&((*query)->acf->name), "%s_%s", tmp, catg) < 0) {
|
if (ast_asprintf((char **)&((*query)->acf->name), "%s_%s", tmp, catg) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
(*query)->acf->name = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (asprintf((char **)&((*query)->acf->name), "ODBC_%s", catg) < 0) {
|
if (ast_asprintf((char **)&((*query)->acf->name), "ODBC_%s", catg) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
(*query)->acf->name = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
main/file.c
16
main/file.c
@@ -263,14 +263,12 @@ static char *build_filename(const char *filename, const char *ext)
|
|||||||
ext = "WAV";
|
ext = "WAV";
|
||||||
|
|
||||||
if (filename[0] == '/') {
|
if (filename[0] == '/') {
|
||||||
if (asprintf(&fn, "%s.%s", filename, ext) < 0) {
|
if (ast_asprintf(&fn, "%s.%s", filename, ext) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
fn = NULL;
|
fn = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (asprintf(&fn, "%s/sounds/%s.%s",
|
if (ast_asprintf(&fn, "%s/sounds/%s.%s",
|
||||||
ast_config_AST_DATA_DIR, filename, ext) < 0) {
|
ast_config_AST_DATA_DIR, filename, ext) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
fn = NULL;
|
fn = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1010,6 +1008,9 @@ struct ast_filestream *ast_readfile(const char *filename, const char *type, cons
|
|||||||
format_found = 1;
|
format_found = 1;
|
||||||
|
|
||||||
fn = build_filename(filename, type);
|
fn = build_filename(filename, type);
|
||||||
|
if (!fn) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
bfile = fopen(fn, "r");
|
bfile = fopen(fn, "r");
|
||||||
|
|
||||||
@@ -1030,6 +1031,7 @@ struct ast_filestream *ast_readfile(const char *filename, const char *type, cons
|
|||||||
fs->mode = mode;
|
fs->mode = mode;
|
||||||
fs->filename = ast_strdup(filename);
|
fs->filename = ast_strdup(filename);
|
||||||
fs->vfs = NULL;
|
fs->vfs = NULL;
|
||||||
|
ast_free(fn);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1077,6 +1079,9 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
|
|||||||
format_found = 1;
|
format_found = 1;
|
||||||
|
|
||||||
fn = build_filename(filename, type);
|
fn = build_filename(filename, type);
|
||||||
|
if (!fn) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
fd = open(fn, flags | myflags, mode);
|
fd = open(fn, flags | myflags, mode);
|
||||||
if (fd > -1) {
|
if (fd > -1) {
|
||||||
/* fdopen() the resulting file stream */
|
/* fdopen() the resulting file stream */
|
||||||
@@ -1138,6 +1143,9 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
|
|||||||
ast_closestream(fs);
|
ast_closestream(fs);
|
||||||
fs = NULL;
|
fs = NULL;
|
||||||
}
|
}
|
||||||
|
if (!buf) {
|
||||||
|
ast_free(fn);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fs->trans = NULL;
|
fs->trans = NULL;
|
||||||
|
|||||||
@@ -1050,9 +1050,8 @@ int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*st
|
|||||||
a->start_routine = start_routine;
|
a->start_routine = start_routine;
|
||||||
a->data = data;
|
a->data = data;
|
||||||
start_routine = dummy_start;
|
start_routine = dummy_start;
|
||||||
if (asprintf(&a->name, "%-20s started at [%5d] %s %s()",
|
if (ast_asprintf(&a->name, "%-20s started at [%5d] %s %s()",
|
||||||
start_fn, line, file, caller) < 0) {
|
start_fn, line, file, caller) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
a->name = NULL;
|
a->name = NULL;
|
||||||
}
|
}
|
||||||
data = a;
|
data = a;
|
||||||
|
|||||||
@@ -691,7 +691,9 @@ static char *xmldoc_get_syntax_fun(struct ast_xml_node *rootnode, const char *ro
|
|||||||
|
|
||||||
if (!rootnode || !ast_xml_node_get_children(rootnode)) {
|
if (!rootnode || !ast_xml_node_get_children(rootnode)) {
|
||||||
/* If the rootnode field is not found, at least print name. */
|
/* If the rootnode field is not found, at least print name. */
|
||||||
ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : ""));
|
if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) {
|
||||||
|
syntax = NULL;
|
||||||
|
}
|
||||||
return syntax;
|
return syntax;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,7 +733,9 @@ static char *xmldoc_get_syntax_fun(struct ast_xml_node *rootnode, const char *ro
|
|||||||
|
|
||||||
if (!hasparams) {
|
if (!hasparams) {
|
||||||
/* This application, function, option, etc, doesn't have any params. */
|
/* This application, function, option, etc, doesn't have any params. */
|
||||||
ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : ""));
|
if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) {
|
||||||
|
syntax = NULL;
|
||||||
|
}
|
||||||
return syntax;
|
return syntax;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -803,13 +807,19 @@ static char *xmldoc_get_syntax_fun(struct ast_xml_node *rootnode, const char *ro
|
|||||||
ast_free(syntax);
|
ast_free(syntax);
|
||||||
}
|
}
|
||||||
/* to give up is ok? */
|
/* to give up is ok? */
|
||||||
ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : ""));
|
if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) {
|
||||||
|
syntax = NULL;
|
||||||
|
}
|
||||||
return syntax;
|
return syntax;
|
||||||
}
|
}
|
||||||
paramname = ast_strdup(paramnameattr);
|
paramname = ast_strdup(paramnameattr);
|
||||||
ast_xml_free_attr(paramnameattr);
|
ast_xml_free_attr(paramnameattr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!paramname) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Defaults to 'false'. */
|
/* Defaults to 'false'. */
|
||||||
multiple = 0;
|
multiple = 0;
|
||||||
if ((multipletype = ast_xml_get_attribute(node, "multiple"))) {
|
if ((multipletype = ast_xml_get_attribute(node, "multiple"))) {
|
||||||
@@ -1407,8 +1417,7 @@ static int xmldoc_parse_variablelist(struct ast_xml_node *node, const char *tabs
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* use this spacing (add 4 spaces) inside a variablelist node. */
|
/* use this spacing (add 4 spaces) inside a variablelist node. */
|
||||||
ast_asprintf(&vartabs, "%s ", tabs);
|
if (ast_asprintf(&vartabs, "%s ", tabs) < 0) {
|
||||||
if (!vartabs) {
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
|
for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
|
||||||
@@ -1525,7 +1534,9 @@ static int xmldoc_parse_enum(struct ast_xml_node *fixnode, const char *tabs, str
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *optiontabs;
|
char *optiontabs;
|
||||||
|
|
||||||
ast_asprintf(&optiontabs, "%s ", tabs);
|
if (ast_asprintf(&optiontabs, "%s ", tabs) < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
|
for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
|
||||||
if ((xmldoc_parse_para(node, (ret ? tabs : " - "), "\n", buffer))) {
|
if ((xmldoc_parse_para(node, (ret ? tabs : " - "), "\n", buffer))) {
|
||||||
@@ -1591,8 +1602,7 @@ static int xmldoc_parse_option(struct ast_xml_node *fixnode, const char *tabs, s
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *optiontabs;
|
char *optiontabs;
|
||||||
|
|
||||||
ast_asprintf(&optiontabs, "%s ", tabs);
|
if (ast_asprintf(&optiontabs, "%s ", tabs) < 0) {
|
||||||
if (!optiontabs) {
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
|
for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
|
||||||
@@ -1698,8 +1708,8 @@ static void xmldoc_parse_parameter(struct ast_xml_node *fixnode, const char *tab
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_asprintf(&internaltabs, "%s ", tabs);
|
if (ast_asprintf(&internaltabs, "%s ", tabs) < 0) {
|
||||||
if (!internaltabs) {
|
ast_xml_free_attr(paramname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1983,8 +1993,10 @@ int ast_xmldoc_load_documentation(void)
|
|||||||
globret = xml_pathmatch(xmlpattern, xmlpattern_maxlen, &globbuf);
|
globret = xml_pathmatch(xmlpattern, xmlpattern_maxlen, &globbuf);
|
||||||
#else
|
#else
|
||||||
/* Get every *-LANG.xml file inside $(ASTDATADIR)/documentation */
|
/* Get every *-LANG.xml file inside $(ASTDATADIR)/documentation */
|
||||||
ast_asprintf(&xmlpattern, "%s/documentation{/thirdparty/,/}*-{%s,%.2s_??,%s}.xml", ast_config_AST_DATA_DIR,
|
if (ast_asprintf(&xmlpattern, "%s/documentation{/thirdparty/,/}*-{%s,%.2s_??,%s}.xml", ast_config_AST_DATA_DIR,
|
||||||
documentation_language, documentation_language, default_documentation_language);
|
documentation_language, documentation_language, default_documentation_language) < 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
globret = glob(xmlpattern, MY_GLOB_FLAGS, NULL, &globbuf);
|
globret = glob(xmlpattern, MY_GLOB_FLAGS, NULL, &globbuf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -435,14 +435,12 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
|
|||||||
if (++which > a->n) {
|
if (++which > a->n) {
|
||||||
/* If there is an extension then return exten@context. */
|
/* If there is an extension then return exten@context. */
|
||||||
if (ast_get_extension_matchcid(e) && (!strchr(a->word, '@') || strchr(a->word, '/'))) {
|
if (ast_get_extension_matchcid(e) && (!strchr(a->word, '@') || strchr(a->word, '/'))) {
|
||||||
if (asprintf(&ret, "%s/%s@%s", ast_get_extension_name(e), ast_get_extension_cidmatch(e), ast_get_context_name(c)) < 0) {
|
if (ast_asprintf(&ret, "%s/%s@%s", ast_get_extension_name(e), ast_get_extension_cidmatch(e), ast_get_context_name(c)) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (!ast_get_extension_matchcid(e) && !strchr(a->word, '/')) {
|
} else if (!ast_get_extension_matchcid(e) && !strchr(a->word, '/')) {
|
||||||
if (asprintf(&ret, "%s@%s", ast_get_extension_name(e), ast_get_context_name(c)) < 0) {
|
if (ast_asprintf(&ret, "%s@%s", ast_get_extension_name(e), ast_get_context_name(c)) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -668,13 +668,13 @@ static struct sqlite_cache_tables *find_table(const char *tablename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Table structure not cached; build the structure now */
|
/* Table structure not cached; build the structure now */
|
||||||
if (asprintf(&sql, sql_table_structure, tablename) < 0) {
|
if (ast_asprintf(&sql, sql_table_structure, tablename) < 0) {
|
||||||
ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
|
|
||||||
sql = NULL;
|
sql = NULL;
|
||||||
}
|
}
|
||||||
if (!(tblptr = ast_calloc(1, sizeof(*tblptr) + strlen(tablename) + 1))) {
|
if (!(tblptr = ast_calloc(1, sizeof(*tblptr) + strlen(tablename) + 1))) {
|
||||||
AST_RWLIST_UNLOCK(&sqlite_tables);
|
AST_RWLIST_UNLOCK(&sqlite_tables);
|
||||||
ast_log(LOG_ERROR, "Memory error. Cannot cache table '%s'\n", tablename);
|
ast_log(LOG_ERROR, "Memory error. Cannot cache table '%s'\n", tablename);
|
||||||
|
ast_free(sql);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
tblptr->name = (char *)tblptr + sizeof(*tblptr);
|
tblptr->name = (char *)tblptr + sizeof(*tblptr);
|
||||||
@@ -690,9 +690,11 @@ static struct sqlite_cache_tables *find_table(const char *tablename)
|
|||||||
ast_free(errstr);
|
ast_free(errstr);
|
||||||
free_table(tblptr);
|
free_table(tblptr);
|
||||||
AST_RWLIST_UNLOCK(&sqlite_tables);
|
AST_RWLIST_UNLOCK(&sqlite_tables);
|
||||||
|
ast_free(sql);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&mutex);
|
ast_mutex_unlock(&mutex);
|
||||||
|
ast_free(sql);
|
||||||
|
|
||||||
if (AST_LIST_EMPTY(&(tblptr->columns))) {
|
if (AST_LIST_EMPTY(&(tblptr->columns))) {
|
||||||
free_table(tblptr);
|
free_table(tblptr);
|
||||||
|
|||||||
@@ -1719,11 +1719,9 @@ static int aji_act_hook(void *data, int type, iks *node)
|
|||||||
|
|
||||||
sprintf(secret, "%s%s", pak->id, client->password);
|
sprintf(secret, "%s%s", pak->id, client->password);
|
||||||
ast_sha1_hash(shasum, secret);
|
ast_sha1_hash(shasum, secret);
|
||||||
handshake = NULL;
|
if (ast_asprintf(&handshake, "<handshake>%s</handshake>", shasum) >= 0) {
|
||||||
if (asprintf(&handshake, "<handshake>%s</handshake>", shasum) >= 0) {
|
|
||||||
aji_send_raw(client, handshake);
|
aji_send_raw(client, handshake);
|
||||||
ast_free(handshake);
|
ast_free(handshake);
|
||||||
handshake = NULL;
|
|
||||||
}
|
}
|
||||||
client->state = AJI_CONNECTING;
|
client->state = AJI_CONNECTING;
|
||||||
if (aji_recv(client, 1) == 2) /*XXX proper result for iksemel library on iks_recv of <handshake/> XXX*/
|
if (aji_recv(client, 1) == 2) /*XXX proper result for iksemel library on iks_recv of <handshake/> XXX*/
|
||||||
@@ -4415,8 +4413,7 @@ static int aji_create_client(char *label, struct ast_variable *var, int debug)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strchr(client->user, '/') && !client->component) { /*client */
|
if (!strchr(client->user, '/') && !client->component) { /*client */
|
||||||
resource = NULL;
|
if (ast_asprintf(&resource, "%s/asterisk", client->user) >= 0) {
|
||||||
if (asprintf(&resource, "%s/asterisk", client->user) >= 0) {
|
|
||||||
client->jid = iks_id_new(client->stack, resource);
|
client->jid = iks_id_new(client->stack, resource);
|
||||||
ast_free(resource);
|
ast_free(resource);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user