start working through memory bugs
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 77c1a8a..0dc5cd4 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -1765,6 +1765,24 @@
 #endif

     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 )

 {

@@ -1949,9 +1967,9 @@
             _entityFlag[ (int)entities[i].value ] = true;

         }

     }

-    _restrictedEntityFlag[(int)'&'] = true;

-    _restrictedEntityFlag[(int)'<'] = true;

-    _restrictedEntityFlag[(int)'>'] = true;	// not required, but consistency is nice

+    _restrictedEntityFlag['&'] = true;

+    _restrictedEntityFlag['<'] = true;

+    _restrictedEntityFlag['>'] = true;	// not required, but consistency is nice

     _buffer.Push( 0 );

 }

 

diff --git a/tinyxml2.h b/tinyxml2.h
index 54190c9..dd1b2cd 100755
--- a/tinyxml2.h
+++ b/tinyxml2.h
@@ -1555,7 +1555,11 @@
 

     /**

     	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

     	an errorID.

@@ -1665,11 +1669,7 @@
     	Delete a node associated with this document.

     	It will be unlinked from the DOM.

     */

-    void DeleteNode( XMLNode* node )	{

-        TIXMLASSERT( node );

-        TIXMLASSERT( node->_parent );

-        node->_parent->DeleteChild( node );

-    }

+    void DeleteNode( XMLNode* node );

 

     void SetError( XMLError error, const char* str1, const char* str2 );

 

diff --git a/xmltest.cpp b/xmltest.cpp
index 18fa8c9..ebcd4dd 100644
--- a/xmltest.cpp
+++ b/xmltest.cpp
@@ -1334,10 +1334,10 @@
 

 	{

 		// Test that it doesn't crash.

-		const char* xml = "<?xml version=\"1.0\"?><root><sample><field0><1</field0><field1>2</field1></sample></root>";
-		XMLDocument doc;
-		doc.Parse(xml);
-		doc.PrintError();
+		const char* xml = "<?xml version=\"1.0\"?><root><sample><field0><1</field0><field1>2</field1></sample></root>";

+		XMLDocument doc;

+		doc.Parse(xml);

+		doc.PrintError();

 	}

 

 #if 1

@@ -1390,6 +1390,13 @@
             doc.Clear();

         }

     }

+    

+    {

+        // If this doesn't assert in DEBUG, all is well.

+        tinyxml2::XMLDocument doc;

+        tinyxml2::XMLElement *pRoot = doc.NewElement("Root");

+        doc.DeleteNode(pRoot);

+    }

 

 

 	// ----------- Performance tracking --------------