Fix string leaking (and destructors not getting called) when there are XMLNodes that aren't in the document tree

This commit is contained in:
Lee Thomason
2017-06-05 14:35:55 -07:00
parent 53858b4490
commit 816d3fa0cd
3 changed files with 63 additions and 3 deletions

View File

@@ -264,6 +264,12 @@ public:
return _allocated;
}
void SwapRemove(int i) {
TIXMLASSERT(i < _size);
_mem[i] = _mem[_size - 1];
--_size;
}
const T* Mem() const {
TIXMLASSERT( _mem );
return _mem;
@@ -1802,6 +1808,9 @@ public:
// internal
char* Identify( char* p, XMLNode** node );
// internal
void MarkInUse(XMLNode*);
virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
return 0;
}
@@ -1822,6 +1831,13 @@ private:
int _errorLineNum;
char* _charBuffer;
int _parseCurLineNum;
// Memory tracking does add some overhead.
// However, the code assumes that you don't
// have a bunch of unlinked nodes around.
// Therefore it takes less memory to track
// in the document vs. a linked list in the XMLNode,
// and the performance is the same.
DynArray<XMLNode*, 10> _unlinked;
MemPoolT< sizeof(XMLElement) > _elementPool;
MemPoolT< sizeof(XMLAttribute) > _attributePool;
@@ -1844,6 +1860,8 @@ inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& poo
NodeType* returnNode = new (pool.Alloc()) NodeType( this );
TIXMLASSERT( returnNode );
returnNode->_memPool = &pool;
_unlinked.Push(returnNode);
return returnNode;
}