start working through memory bugs

This commit is contained in:
Lee Thomason 2014-12-17 10:41:34 -08:00
parent ee2c46928e
commit cd011bc1b7
3 changed files with 38 additions and 13 deletions

View File

@ -1766,6 +1766,24 @@ static FILE* callfopen( const char* filepath, const char* mode )
return fp; return fp;
} }
void XMLDocument::DeleteNode( XMLNode* node ) {
TIXMLASSERT( node );
TIXMLASSERT(node->_document == this );
if (node->_parent) {
node->_parent->DeleteChild( node );
}
else {
// Isn't in the tree.
// Use the parent delete.
// Also, we need to mark it tracked: we 'know'
// it was never used.
node->_memPool->SetTracked();
// Call the static XMLNode version:
XMLNode::DeleteNode(node);
}
}
XMLError XMLDocument::LoadFile( const char* filename ) XMLError XMLDocument::LoadFile( const char* filename )
{ {
Clear(); Clear();
@ -1949,9 +1967,9 @@ XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
_entityFlag[ (int)entities[i].value ] = true; _entityFlag[ (int)entities[i].value ] = true;
} }
} }
_restrictedEntityFlag[(int)'&'] = true; _restrictedEntityFlag['&'] = true;
_restrictedEntityFlag[(int)'<'] = true; _restrictedEntityFlag['<'] = true;
_restrictedEntityFlag[(int)'>'] = true; // not required, but consistency is nice _restrictedEntityFlag['>'] = true; // not required, but consistency is nice
_buffer.Push( 0 ); _buffer.Push( 0 );
} }

View File

@ -1557,6 +1557,10 @@ public:
Load an XML file from disk. You are responsible Load an XML file from disk. You are responsible
for providing and closing the FILE*. for providing and closing the FILE*.
NOTE: The file should be opened as binary ("rb")
not text in order for TinyXML-2 to correctly
do newline normalization.
Returns XML_NO_ERROR (0) on success, or Returns XML_NO_ERROR (0) on success, or
an errorID. an errorID.
*/ */
@ -1665,11 +1669,7 @@ public:
Delete a node associated with this document. Delete a node associated with this document.
It will be unlinked from the DOM. It will be unlinked from the DOM.
*/ */
void DeleteNode( XMLNode* node ) { void DeleteNode( XMLNode* node );
TIXMLASSERT( node );
TIXMLASSERT( node->_parent );
node->_parent->DeleteChild( node );
}
void SetError( XMLError error, const char* str1, const char* str2 ); void SetError( XMLError error, const char* str1, const char* str2 );

View File

@ -1391,6 +1391,13 @@ int main( int argc, const char ** argv )
} }
} }
{
// If this doesn't assert in DEBUG, all is well.
tinyxml2::XMLDocument doc;
tinyxml2::XMLElement *pRoot = doc.NewElement("Root");
doc.DeleteNode(pRoot);
}
// ----------- Performance tracking -------------- // ----------- Performance tracking --------------
{ {