Merge branch 'master' of https://github.com/leethomason/tinyxml2
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index fb367fc..598102b 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -1728,9 +1728,8 @@
         }

     }

     if ( !attrib ) {

-        TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );

-        attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();

-        attrib->_memPool = &_document->_attributePool;

+        attrib = CreateAttribute();

+        TIXMLASSERT( attrib );

         if ( last ) {

             last->_next = attrib;

         }

@@ -1738,7 +1737,6 @@
             _rootAttribute = attrib;

         }

         attrib->SetName( name );

-        attrib->_memPool->SetTracked(); // always created and linked.

     }

     return attrib;

 }

@@ -1778,11 +1776,9 @@
 

         // attribute.

         if (XMLUtil::IsNameStartChar( *p ) ) {

-            TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );

-            XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();

+            XMLAttribute* attrib = CreateAttribute();

+            TIXMLASSERT( attrib );

             attrib->_parseLineNum = _document->_parseCurLineNum;

-            attrib->_memPool = &_document->_attributePool;

-			attrib->_memPool->SetTracked();

 

             int attrLineNum = attrib->_parseLineNum;

 

@@ -1833,6 +1829,15 @@
     pool->Free( attribute );

 }

 

+XMLAttribute* XMLElement::CreateAttribute()

+{

+    TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );

+    XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();

+    attrib->_memPool = &_document->_attributePool;

+    attrib->_memPool->SetTracked();

+    return attrib;

+}

+

 //

 //	<ele></ele>

 //	<ele>foo<b>bar</b></ele>

@@ -1972,10 +1977,7 @@
 #ifdef DEBUG

     const bool hadError = Error();

 #endif

-    _errorID = XML_SUCCESS;

-	_errorStr1.Reset();

-	_errorStr2.Reset();

-    _errorLineNum = 0;

+    ClearError();

 

     delete [] _charBuffer;

     _charBuffer = 0;

@@ -2180,7 +2182,7 @@
 {

     // Clear any error from the last save, otherwise it will get reported

     // for *this* call.

-	SetError(XML_SUCCESS, 0, 0, 0);

+    ClearError();

     XMLPrinter stream( fp, compact );

     Print( &stream );

     return _errorID;

diff --git a/tinyxml2.h b/tinyxml2.h
index b15da9e..e176ec0 100755
--- a/tinyxml2.h
+++ b/tinyxml2.h
@@ -1574,6 +1574,7 @@
     //void LinkAttribute( XMLAttribute* attrib );

     char* ParseAttributes( char* p, int& curLineNum );

     static void DeleteAttribute( XMLAttribute* attribute );

+    XMLAttribute* CreateAttribute();

 

     enum { BUF_SIZE = 200 };

     int _closingType;

@@ -1751,6 +1752,10 @@
 

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

 

+    void ClearError() {

+        SetError(XML_SUCCESS, 0, 0, 0);

+    }

+

     /// Return true if there was an error parsing the document.

     bool Error() const {

         return _errorID != XML_SUCCESS;