[libxml++] free_wrappers(): Fix crash.



commit c8e34c3de03c2b41e825e392247efc1ea8698fbf
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Nov 14 21:53:11 2010 +0100

    free_wrappers(): Fix crash.
    
    * libxml++/nodes/node.cc: free_wrappers(): Revert my change to check
    xmlNode::properties for all types, because the layout of some structs
    is apparently completely different (not really deriving fully), and this
    caused a crash in examples/sax_parser/.
    Added an explanatory comment.

 ChangeLog              |   10 ++++++++++
 libxml++/nodes/node.cc |   12 ++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f7acf78..d9f9567 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2010-11-14  Murray Cumming  <murrayc murrayc com>
 
+	free_wrappers(): Fix crash.
+
+	* libxml++/nodes/node.cc: free_wrappers(): Revert my change to check 
+	xmlNode::properties for all types, because the layout of some structs 
+	is apparently completely different (not really deriving fully), and this 
+	caused a crash in examples/sax_parser/.
+	Added an explanatory comment.
+
+2010-11-14  Murray Cumming  <murrayc murrayc com>
+
 	Change the --enable-examples default to yes.
 
 	* configure.ac: Build the examples by default, so we at least check the 
diff --git a/libxml++/nodes/node.cc b/libxml++/nodes/node.cc
index ab22bbf..cbf1008 100644
--- a/libxml++/nodes/node.cc
+++ b/libxml++/nodes/node.cc
@@ -484,24 +484,28 @@ void Node::free_wrappers(xmlNode* node)
     case XML_DTD_NODE:
       delete static_cast<Dtd*>(node->_private);
       node->_private = 0;
-      break;
+      return;
     case XML_ATTRIBUTE_NODE:
     case XML_ELEMENT_DECL:
     case XML_ATTRIBUTE_DECL:
     case XML_ENTITY_DECL:
       delete static_cast<Node*>(node->_private);
       node->_private = 0;
-      break;
+      return;
     case XML_DOCUMENT_NODE:
       //Do not free now. The Document is usually the one who owns the caller.
-      break;
+      return;
     default:
       delete static_cast<Node*>(node->_private);
       node->_private = 0;
       break;
   }
 
-  //Walk the attributes list
+  //Walk the attributes list.
+  //Note that some "derived" struct have a different layout, so 
+  //_xmlNode::properties would be a nonsense value, leading to crashes,
+  //(and shown as valgrind warnings), so we return above, to avoid 
+  //checking it here.
   for(xmlAttr* attr = node->properties; attr; attr = attr->next)
     free_wrappers(reinterpret_cast<xmlNode*>(attr));
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]