From 710ece7d0f537ffe42fa767e5725ab6945362e7e Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Thu, 22 Sep 2011 00:00:14 +0200 Subject: [PATCH 1/1] Fix the last memory leaks from the clone test. --- c++0x/xml-template.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/c++0x/xml-template.cpp b/c++0x/xml-template.cpp index 96f0270..c1d43ed 100644 --- a/c++0x/xml-template.cpp +++ b/c++0x/xml-template.cpp @@ -17,6 +17,9 @@ void clean_node(xmlNode *node) xmlReplaceNode(node, frag); frag->children = node->children; frag->last = node->last; + + node->children = node->last = NULL; + xmlFreeNode(node); } } @@ -92,7 +95,9 @@ Substitute::~Substitute() void Substitute::process(xmlNode *node, bool clean) { - for (xmlNode *child = node->children; child != NULL; child = child->next) { + xmlNode *next_child; + for (xmlNode *child = node->children; child != NULL; child = next_child) { + next_child = child->next; bool processed = false; if (child->type == XML_ELEMENT_NODE) { @@ -122,7 +127,7 @@ void Substitute::process(xmlNode *node, bool clean) } } } - + if (!processed) { process(child, clean); } -- 2.39.2