Merge pull request #321 from Dmitry-Me/dontLeakTheElement
Don't leak the element
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 0619bdf..a536abf 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -550,14 +550,14 @@
// These strings define the matching patters:
static const char* xmlHeader = { "<?" };
static const char* commentHeader = { "<!--" };
- static const char* dtdHeader = { "<!" };
static const char* cdataHeader = { "<![CDATA[" };
+ static const char* dtdHeader = { "<!" };
static const char* elementHeader = { "<" }; // and a header for everything else; check last.
static const int xmlHeaderLen = 2;
static const int commentHeaderLen = 4;
- static const int dtdHeaderLen = 2;
static const int cdataHeaderLen = 9;
+ static const int dtdHeaderLen = 2;
static const int elementHeaderLen = 1;
TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool
@@ -662,6 +662,7 @@
void XMLNode::DeleteChildren()
{
while( _firstChild ) {
+ TIXMLASSERT( _lastChild );
TIXMLASSERT( _firstChild->_document == _document );
XMLNode* node = _firstChild;
Unlink( node );
@@ -676,6 +677,7 @@
{
TIXMLASSERT( child );
TIXMLASSERT( child->_document == _document );
+ TIXMLASSERT( child->_parent == this );
if ( child == _firstChild ) {
_firstChild = _firstChild->_next;
}
@@ -2302,11 +2304,11 @@
bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
{
- const XMLElement* parentElem = NULL;
- if ( element.Parent() ) {
- parentElem = element.Parent()->ToElement();
+ const XMLElement* parentElem = 0;
+ if ( element.Parent() ) {
+ parentElem = element.Parent()->ToElement();
}
- bool compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;
+ const bool compactMode = parentElem ? CompactMode( *parentElem ) : _compactMode;
OpenElement( element.Name(), compactMode );
while ( attribute ) {
PushAttribute( attribute->Name(), attribute->Value() );