|
|
@@ -797,9 +797,11 @@ void XMLNode::Unlink( XMLNode* child )
|
|
|
|
|
|
if ( child->_prev ) {
|
|
|
child->_prev->_next = child->_next;
|
|
|
+ child->_prev = 0;
|
|
|
}
|
|
|
if ( child->_next ) {
|
|
|
child->_next->_prev = child->_prev;
|
|
|
+ child->_next = 0;
|
|
|
}
|
|
|
child->_parent = 0;
|
|
|
}
|
|
|
@@ -811,6 +813,9 @@ void XMLNode::DeleteChild( XMLNode* node )
|
|
|
TIXMLASSERT( node->_document == _document );
|
|
|
TIXMLASSERT( node->_parent == this );
|
|
|
Unlink( node );
|
|
|
+ TIXMLASSERT(node->_prev == 0);
|
|
|
+ TIXMLASSERT(node->_next == 0);
|
|
|
+ TIXMLASSERT(node->_parent == 0);
|
|
|
DeleteNode( node );
|
|
|
}
|
|
|
|
|
|
@@ -1055,11 +1060,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-void XMLNode::DeleteNode( XMLNode* node )
|
|
|
+/*static*/ void XMLNode::DeleteNode( XMLNode* node )
|
|
|
{
|
|
|
if ( node == 0 ) {
|
|
|
return;
|
|
|
}
|
|
|
+ TIXMLASSERT(node->_document);
|
|
|
+ if (!node->ToDocument()) {
|
|
|
+ node->_document->MarkInUse(node);
|
|
|
+ }
|
|
|
+
|
|
|
MemPool* pool = node->_memPool;
|
|
|
node->~XMLNode();
|
|
|
pool->Free( node );
|
|
|
@@ -1070,10 +1080,13 @@ void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const
|
|
|
TIXMLASSERT( insertThis );
|
|
|
TIXMLASSERT( insertThis->_document == _document );
|
|
|
|
|
|
- if ( insertThis->_parent )
|
|
|
+ if (insertThis->_parent) {
|
|
|
insertThis->_parent->Unlink( insertThis );
|
|
|
- else
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ insertThis->_document->MarkInUse(insertThis);
|
|
|
insertThis->_memPool->SetTracked();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const XMLElement* XMLNode::ToElementWithName( const char* name ) const
|
|
|
@@ -1979,9 +1992,24 @@ XMLDocument::~XMLDocument()
|
|
|
}
|
|
|
|
|
|
|
|
|
+void XMLDocument::MarkInUse(XMLNode* node)
|
|
|
+{
|
|
|
+ TIXMLASSERT(node->_parent == 0);
|
|
|
+
|
|
|
+ for (int i = 0; i < _unlinked.Size(); ++i) {
|
|
|
+ if (node == _unlinked[i]) {
|
|
|
+ _unlinked.SwapRemove(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void XMLDocument::Clear()
|
|
|
{
|
|
|
DeleteChildren();
|
|
|
+ while( _unlinked.Size()) {
|
|
|
+ DeleteNode(_unlinked[0]); // Will remove from _unlinked as part of delete.
|
|
|
+ }
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
const bool hadError = Error();
|