]> git.sesse.net Git - xml-template/commitdiff
Fix an attribute leak in the C++0x code.
authorsgunderson@bigfoot.com <>
Wed, 21 Sep 2011 21:50:16 +0000 (23:50 +0200)
committersgunderson@bigfoot.com <>
Wed, 21 Sep 2011 21:50:16 +0000 (23:50 +0200)
c++0x/xml-template.cpp

index c2b62cd77ecbb6da8441e938809bb4042120c453..e6e88a30a31e1347deb1ab3b3e78bac34bd72493 100644 (file)
@@ -95,20 +95,17 @@ void Substitute::process(xmlNode *node, bool clean)
                if (child->type == XML_ELEMENT_NODE) {
                        // Find the ID, if any.
                        string id;
+                       xmlAttr *id_attr = NULL;
                        for (xmlAttr *attr = child->properties; attr != NULL; attr = attr->next) {
                                if (strcmp(reinterpret_cast<const char *>(attr->ns->href), "http://template.sesse.net/") == 0 &&
                                    strcmp(reinterpret_cast<const char *>(attr->name), "id") == 0) {
                                        id = reinterpret_cast<const char *>(xmlNodeGetContent(attr->children));
-
-                                       if (clean) {
-                                               if (attr->prev == NULL) {
-                                                       child->properties = attr->next;
-                                               } else {
-                                                       attr->prev->next = attr->next;
-                                               }
-                                       }
+                                       id_attr = attr;
                                }
                        }
+                       if (clean && id_attr != NULL) {
+                               xmlRemoveProp(id_attr);
+                       }
 
                        // Check all substitutions to see if we found anything appropriate.
                        for (auto it : substitution_map) {