]> git.sesse.net Git - xml-template/blobdiff - c++0x/xml-template.cpp
Fix the worst (but not all) memory leaks in the C++0x version.
[xml-template] / c++0x / xml-template.cpp
index ac686502afc6e06b064f04938bfcb69662e675ff..a6a7316846db452bdf03e364f9f81a830486aa72 100644 (file)
@@ -21,6 +21,8 @@ void clean_node(xmlNode *node)
 
 }  // namespace
 
+Directive::~Directive() {}
+
 Replace::Replace(const string &str)
        : str(str) {}
 
@@ -37,6 +39,13 @@ Clone::Clone(const vector<Directive *> &subdirectives)
 Clone::Clone(initializer_list<Directive *> subdirectives)
        : subdirectives(subdirectives) {}
 
+Clone::~Clone()
+{
+       for (auto it : subdirectives) {
+               delete it;
+       }
+}
+
 void Clone::process(xmlNode *node, bool clean)
 {
        // We can't use xmlNewDocFragment, since xmlDOMWrapCloneNode only knows
@@ -67,6 +76,13 @@ Substitute::Substitute(const unordered_map<string, Directive*> &substitution_map
 Substitute::Substitute(initializer_list<pair<const string, Directive*>> substitution_map)
        : substitution_map(substitution_map) {}
 
+Substitute::~Substitute()
+{
+       for (auto it : substitution_map) {
+               delete it.second;
+       }
+}
+
 void Substitute::process(xmlNode *node, bool clean)
 {
        for (xmlNode *child = node->children; child != NULL; child = child->next) {
@@ -119,6 +135,7 @@ void process_file(const string &input_filename,
        xmlDocPtr doc = xmlParseFile(input_filename.c_str());
        root_directive->process(xmlDocGetRootElement(doc), true);
        xmlSaveFile(output_filename.c_str(), doc);
+       xmlFreeDoc(doc);
 
        xmlCleanupParser();
        xmlMemoryDump();