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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 30 06:55:00 CDT 2008


Author: eliel
Date: Tue Sep 30 06:54:59 2008
New Revision: 145184

URL: http://svn.digium.com/view/asterisk?view=rev&rev=145184
Log:
Fix a leak while trying to return the ->str pointer inside an ast_str structure,
first duplicate the string, and then free the structure used memory (not needed anymore).
Also return NULL if the string inside ast_str is NULL (this is needed to print 'Not available' if some
field has no documentation.

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=145184&r1=145183&r2=145184
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Tue Sep 30 06:54:59 2008
@@ -3898,6 +3898,7 @@
 {
 	ast_xml_node *node;
 	struct ast_str *ret = ast_str_create(1);
+	char *retstr = NULL;
 	
 	if (ast_strlen_zero(type) || ast_strlen_zero(name)) {
 		return NULL;
@@ -3929,7 +3930,12 @@
 		node = node->AST_XML_NEXT;
 	}
 
-	return ret->str;
+	if (ret->used > 0) {
+		retstr = ast_strdup(ret->str);
+	}
+	ast_free(ret);
+
+	return retstr;
 }
 
 /*! \internal
@@ -4015,7 +4021,9 @@
 	}
 
 	formatted = xmldoc_get_formatted(node, raw, raw);
-	ret = ast_strdup(formatted->str);
+	if (formatted->used > 0) {
+		ret = ast_strdup(formatted->str);
+	}
 	ast_free(formatted);
 
 	return ret;




More information about the asterisk-commits mailing list