mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-10 11:58:08 +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:
@@ -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 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;
|
||||
}
|
||||
|
||||
@@ -731,7 +733,9 @@ static char *xmldoc_get_syntax_fun(struct ast_xml_node *rootnode, const char *ro
|
||||
|
||||
if (!hasparams) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@@ -803,13 +807,19 @@ static char *xmldoc_get_syntax_fun(struct ast_xml_node *rootnode, const char *ro
|
||||
ast_free(syntax);
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
paramname = ast_strdup(paramnameattr);
|
||||
ast_xml_free_attr(paramnameattr);
|
||||
}
|
||||
|
||||
if (!paramname) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Defaults to 'false'. */
|
||||
multiple = 0;
|
||||
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. */
|
||||
ast_asprintf(&vartabs, "%s ", tabs);
|
||||
if (!vartabs) {
|
||||
if (ast_asprintf(&vartabs, "%s ", tabs) < 0) {
|
||||
return ret;
|
||||
}
|
||||
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;
|
||||
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)) {
|
||||
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;
|
||||
char *optiontabs;
|
||||
|
||||
ast_asprintf(&optiontabs, "%s ", tabs);
|
||||
if (!optiontabs) {
|
||||
if (ast_asprintf(&optiontabs, "%s ", tabs) < 0) {
|
||||
return ret;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
ast_asprintf(&internaltabs, "%s ", tabs);
|
||||
if (!internaltabs) {
|
||||
if (ast_asprintf(&internaltabs, "%s ", tabs) < 0) {
|
||||
ast_xml_free_attr(paramname);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1983,8 +1993,10 @@ int ast_xmldoc_load_documentation(void)
|
||||
globret = xml_pathmatch(xmlpattern, xmlpattern_maxlen, &globbuf);
|
||||
#else
|
||||
/* Get every *-LANG.xml file inside $(ASTDATADIR)/documentation */
|
||||
ast_asprintf(&xmlpattern, "%s/documentation{/thirdparty/,/}*-{%s,%.2s_??,%s}.xml", ast_config_AST_DATA_DIR,
|
||||
documentation_language, documentation_language, default_documentation_language);
|
||||
if (ast_asprintf(&xmlpattern, "%s/documentation{/thirdparty/,/}*-{%s,%.2s_??,%s}.xml", ast_config_AST_DATA_DIR,
|
||||
documentation_language, documentation_language, default_documentation_language) < 0) {
|
||||
return 1;
|
||||
}
|
||||
globret = glob(xmlpattern, MY_GLOB_FLAGS, NULL, &globbuf);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user