diff options
author | Matthew Jordan <mjordan@digium.com> | 2012-11-04 00:48:24 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2012-11-04 00:48:24 +0000 |
commit | ff469e9d5d61b8fc2b24b0965182a380fb347155 (patch) | |
tree | db29c71266299102d2d0e81b88c7cbd3043dc3a3 | |
parent | 19282f682ef17ba8e4895e04492bf9f72b5655af (diff) |
Fix memory leaks in XML documentation
This patch fixes two memory leaks:
1) When building XML documentation items, the 'name' attribute was extracted
from XML elements but not properly freed after being copied into the item
being built.
2) When unloading XML documentation, the doctree container objects were not
properly freed.
This patch corrects these memory leaks. Note that this patch was modified
slightly for this commmit, as the case where the 'name' attribute doesn't
exist also wasn't handled in the item construction. This patch also checks
for that attribute not existing.
(closes issue ASTERISK-20648)
Reported by: Corey Farrell
Tested by: mjordan
patches:
xmldoc-memory_leak.patch uploaded by Corey Farrell (license 5909)
........
Merged revisions 375756 from http://svn.asterisk.org/svn/asterisk/branches/11
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@375757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r-- | main/xmldoc.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/main/xmldoc.c b/main/xmldoc.c index 0a8da5896..56f1c74f0 100644 --- a/main/xmldoc.c +++ b/main/xmldoc.c @@ -2251,6 +2251,9 @@ struct ao2_container *ast_xmldoc_build_documentation(const char *type) continue; } name = ast_xml_get_attribute(node, "name"); + if (!name) { + continue; + } switch (xmldoc_get_syntax_type(type)) { case MANAGER_EVENT_SYNTAX: @@ -2276,6 +2279,7 @@ struct ao2_container *ast_xmldoc_build_documentation(const char *type) default: item = xmldoc_build_documentation_item(node, name, type); } + ast_xml_free_attr(name); if (item) { ao2_link(docs, item); @@ -2335,12 +2339,13 @@ static int xml_pathmatch(char *xmlpattern, int xmlpattern_maxlen, glob_t *globbu /*! \brief Close and unload XML documentation. */ static void xmldoc_unload_documentation(void) { - struct documentation_tree *doctree; + struct documentation_tree *doctree; AST_RWLIST_WRLOCK(&xmldoc_tree); while ((doctree = AST_RWLIST_REMOVE_HEAD(&xmldoc_tree, entry))) { ast_free(doctree->filename); ast_xml_close(doctree->doc); + ast_free(doctree); } AST_RWLIST_UNLOCK(&xmldoc_tree); |