[asterisk-commits] eliel: branch group/appdocsxml r150198 - /team/group/appdocsxml/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 16 11:50:47 CDT 2008


Author: eliel
Date: Thu Oct 16 11:50:46 2008
New Revision: 150198

URL: http://svn.digium.com/view/asterisk?view=rev&rev=150198
Log:
Fix a memory leak added in my last commit when using ast_asprintf.
Attribute 'name' in a <parameter> tag is required, so it is not needed to continue parsing the <parameter> if
no 'name' was given.
Cleanup the code (style).

Modified:
    team/group/appdocsxml/main/pbx.c

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=150198&r1=150197&r2=150198
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Thu Oct 16 11:50:46 2008
@@ -4266,14 +4266,15 @@
 		} else if (xmldoc_parse_specialtags(node, (ret ? tabs :  ""), "\n", buffer)) {
 			ret = 1;
 		}
-		
+
 		xmldoc_parse_variablelist(node, optiontabs, buffer);
-		
+
 		xmldoc_parse_enumlist(node, optiontabs, buffer);
 
-		node = node->AST_XML_NEXT;	
-	}
-			
+		node = node->AST_XML_NEXT;
+	}
+	ast_free(optiontabs);
+
 	return ret;
 }
 
@@ -4339,24 +4340,23 @@
 	int hasarguments, printed = 0;
 	char *internaltabs;
 	
-	ast_asprintf(&internaltabs, "%s    ", tabs);
-
 	if (!node || !node->AST_XML_CHILD || strcasecmp((char *)node->AST_XML_NAME, "parameter")) {
 		return;
 	}
 
 	hasarguments = xmldoc_has_arguments(node);
-	paramname = ast_xml_get_attribute(node, "name");
+	if (!(paramname = ast_xml_get_attribute(node, "name"))) {
+		/* parameter MUST have an attribute name. */
+		return;
+	}
 
 	if (!hasarguments) {
-		if (paramname) {
-			ast_str_append(buffer, 0, "%s\n", paramname);
-			ast_xml_free_attr(paramname);
-			printed = 1;
-		} else {
-			return;
-		}
-	}
+		ast_str_append(buffer, 0, "%s\n", paramname);
+		ast_xml_free_attr(paramname);
+		printed = 1;
+	}
+
+	ast_asprintf(&internaltabs, "%s    ", tabs);
 
 	node = node->AST_XML_CHILD;
 	while (node) {
@@ -4368,13 +4368,9 @@
 			xmldoc_parse_argument(node, 1, internaltabs, (!hasarguments ? "        " : ""), buffer);
 		} else if (!strcasecmp((char *)node->AST_XML_NAME, "para")) {
 			if (!printed) {
-				if (paramname) {
-					ast_str_append(buffer, 0, "%s\n", paramname);
-					ast_xml_free_attr(paramname);
-					printed = 1;
-				} else {
-					return;
-				}		
+				ast_str_append(buffer, 0, "%s\n", paramname);
+				ast_xml_free_attr(paramname);
+				printed = 1;
 			}	
 			xmldoc_parse_para(node, internaltabs, "\n", buffer);
 			node = node->AST_XML_NEXT;
@@ -4383,11 +4379,9 @@
 			node = node->AST_XML_NEXT;
 			continue;
 		}
-
 		node = node->AST_XML_NEXT;
 	}
-
-
+	ast_free(internaltabs);
 }
 
 /*! \internal




More information about the asterisk-commits mailing list