From f07b952296e20e93759083018420683855c5fc6c Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Thu, 30 Oct 2014 13:25:12 -0700 Subject: [PATCH] fix issue 184. clean up xcode project. --- tinyxml2.cpp | 45 ++++++++++++--------- tinyxml2.h | 24 ++++++++--- tinyxml2/tinyxml2.xcodeproj/project.pbxproj | 7 ++++ xmltest.cpp | 17 +++++++- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 2893a27..9928444 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1623,24 +1623,7 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) : XMLDocument::~XMLDocument() { - DeleteChildren(); - delete [] _charBuffer; - -#if 0 - _textPool.Trace( "text" ); - _elementPool.Trace( "element" ); - _commentPool.Trace( "comment" ); - _attributePool.Trace( "attribute" ); -#endif - -#ifdef DEBUG - if ( Error() == false ) { - TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() ); - TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() ); - TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() ); - TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() ); - } -#endif + Clear(); } @@ -1654,6 +1637,22 @@ void XMLDocument::Clear() delete [] _charBuffer; _charBuffer = 0; + +#if 0 + _textPool.Trace( "text" ); + _elementPool.Trace( "element" ); + _commentPool.Trace( "comment" ); + _attributePool.Trace( "attribute" ); +#endif + +#ifdef DEBUG + if ( Error() == false ) { + TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() ); + TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() ); + TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() ); + TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() ); + } +#endif } @@ -1821,6 +1820,16 @@ XMLError XMLDocument::Parse( const char* p, size_t len ) ptrdiff_t delta = p - start; // skip initial whitespace, BOM, etc. ParseDeep( _charBuffer+delta, 0 ); + if (_errorID) { + // clean up now essentially dangling memory. + // and the parse fail can put objects in the + // pools that are dead and inaccessible. + DeleteChildren(); + _elementPool.Clear(); + _attributePool.Clear(); + _textPool.Clear(); + _commentPool.Clear(); + } return _errorID; } diff --git a/tinyxml2.h b/tinyxml2.h index 4dfb015..5f8bfcd 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -122,9 +122,9 @@ inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) /* Versioning, past 1.0.14: http://semver.org/ */ -static const int TIXML2_MAJOR_VERSION = 2; -static const int TIXML2_MINOR_VERSION = 2; -static const int TIXML2_PATCH_VERSION = 0; +static const int TIXML2_MAJOR_VERSION = 2; +static const int TIXML2_MINOR_VERSION = 2; +static const int TIXML2_PATCH_VERSION = 0; namespace tinyxml2 { @@ -261,7 +261,7 @@ public: return _mem[i]; } - const T& PeekTop() const { + const T& PeekTop() const { TIXMLASSERT( _size > 0 ); return _mem[ _size - 1]; } @@ -317,6 +317,7 @@ public: virtual void* Alloc() = 0; virtual void Free( void* ) = 0; virtual void SetTracked() = 0; + virtual void Clear() = 0; }; @@ -329,10 +330,20 @@ class MemPoolT : public MemPool public: MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} ~MemPoolT() { + Clear(); + } + + void Clear() { // Delete the blocks. - for( int i=0; i<_blockPtrs.Size(); ++i ) { - delete _blockPtrs[i]; + while( !_blockPtrs.Empty()) { + Block* b = _blockPtrs.Pop(); + delete b; } + _root = 0; + _currentAllocs = 0; + _nAllocs = 0; + _maxAllocs = 0; + _nUntracked = 0; } virtual int ItemSize() const { @@ -365,6 +376,7 @@ public: _nUntracked++; return result; } + virtual void Free( void* mem ) { if ( !mem ) { return; diff --git a/tinyxml2/tinyxml2.xcodeproj/project.pbxproj b/tinyxml2/tinyxml2.xcodeproj/project.pbxproj index cd31274..58c4fcc 100644 --- a/tinyxml2/tinyxml2.xcodeproj/project.pbxproj +++ b/tinyxml2/tinyxml2.xcodeproj/project.pbxproj @@ -96,6 +96,9 @@ /* Begin PBXProject section */ 037AE058151CCC5200E0F29F /* Project object */ = { isa = PBXProject; + attributes = { + LastUpgradeCheck = 0610; + }; buildConfigurationList = 037AE05B151CCC5200E0F29F /* Build configuration list for PBXProject "tinyxml2" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; @@ -134,6 +137,8 @@ buildSettings = { CONFIGURATION_BUILD_DIR = "$(SYMROOT)/Debug"; COPY_PHASE_STRIP = NO; + "GCC_PREPROCESSOR_DEFINITIONS[arch=*]" = DEBUG; + ONLY_ACTIVE_ARCH = YES; SYMROOT = build; }; name = Debug; @@ -156,6 +161,7 @@ GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; INSTALL_PATH = /usr/local/bin; + MACOSX_DEPLOYMENT_TARGET = ""; PREBINDING = NO; PRODUCT_NAME = xmltest; }; @@ -171,6 +177,7 @@ GCC_ENABLE_FIX_AND_CONTINUE = NO; GCC_MODEL_TUNING = G5; INSTALL_PATH = /usr/local/bin; + MACOSX_DEPLOYMENT_TARGET = ""; PREBINDING = NO; PRODUCT_NAME = tinyxml2; ZERO_LINK = NO; diff --git a/xmltest.cpp b/xmltest.cpp index 56b6c82..c57bd79 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1363,7 +1363,22 @@ int main( int argc, const char ** argv ) */ } #endif - + + { + // Issue #184 + // If it doesn't assert, it passes. Caused by objects + // getting created during parsing which are then + // inaccessible in the memory pools. + { + XMLDocument doc; + doc.Parse(""); + } + { + XMLDocument doc; + doc.Parse(""); + doc.Clear(); + } + } // ----------- Performance tracking --------------