From d923c670fcbb6919e415ca4d2b81081e0f83e3f7 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Mon, 23 Jan 2012 08:44:25 -0800 Subject: [PATCH] fix double delete in xml element --- tinyxml2.cpp | 38 +++++++++++++++++++++++--------------- tinyxml2.h | 1 + tinyxml2.suo | Bin 31232 -> 31232 bytes 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index fe1665b..eae8f26 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -188,18 +188,30 @@ XMLNode::XMLNode( XMLDocument* doc ) : XMLNode::~XMLNode() { - XMLNode* node=firstChild; - while( node ) { - XMLNode* temp = node->next; + //printf( "~XMLNode %x\n", this ); + while( firstChild ) { + XMLNode* node = firstChild; + Unlink( node ); delete node; - node = temp; } - if ( prev ) { - prev->next = next; +} + + +void XMLNode::Unlink( XMLNode* child ) +{ + TIXMLASSERT( child->parent == this ); + if ( child == firstChild ) + firstChild = firstChild->next; + if ( child == lastChild ) + lastChild = lastChild->prev; + + if ( child->prev ) { + child->prev->next = child->next; } - if ( next ) { - next->prev = prev; + if ( child->next ) { + child->next->prev = child->prev; } + child->parent = 0; } @@ -254,6 +266,7 @@ XMLComment::XMLComment( XMLDocument* doc ) : XMLNode( doc ) XMLComment::~XMLComment() { + //printf( "~XMLComment\n" ); } @@ -299,19 +312,14 @@ XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ), XMLElement::~XMLElement() { + //printf( "~XMLElemen %x\n",this ); + XMLAttribute* attribute = rootAttribute; while( attribute ) { XMLAttribute* next = attribute->next; delete attribute; attribute = next; } - - XMLNode* child = firstChild; - while( child ) { - XMLNode* next = child->next; - delete child; - child = next; - } } diff --git a/tinyxml2.h b/tinyxml2.h index 779fdde..100ade0 100644 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -122,6 +122,7 @@ public: protected: XMLNode( XMLDocument* ); + void Unlink( XMLNode* child ); XMLDocument* document; XMLNode* parent; diff --git a/tinyxml2.suo b/tinyxml2.suo index 54675ed129421e5bf661b8f825596ebcd1f7e044..77d44eb586664308ba9abd3157ae908c3f346cee 100644 GIT binary patch delta 21 dcmZqp!r1VIaYGIZo5GY2t*>uxE@J5`1psZ=3Mv2q delta 21 dcmZqp!r1VIaYGIZ+kyY