Asserts to ensure old buffer is not leaked when allocating a new one

This commit is contained in:
Dmitry-Me 2015-08-10 16:45:12 +03:00
parent bb8fd3c29c
commit 96f38cca95
1 changed files with 3 additions and 0 deletions

View File

@ -179,6 +179,7 @@ void StrPair::SetStr( const char* str, int flags )
{ {
Reset(); Reset();
size_t len = strlen( str ); size_t len = strlen( str );
TIXMLASSERT( _start == 0 );
_start = new char[ len+1 ]; _start = new char[ len+1 ];
memcpy( _start, str, len+1 ); memcpy( _start, str, len+1 );
_end = _start + len; _end = _start + len;
@ -1944,6 +1945,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
} }
const size_t size = filelength; const size_t size = filelength;
TIXMLASSERT( _charBuffer == 0 );
_charBuffer = new char[size+1]; _charBuffer = new char[size+1];
size_t read = fread( _charBuffer, 1, size, fp ); size_t read = fread( _charBuffer, 1, size, fp );
if ( read != size ) { if ( read != size ) {
@ -1993,6 +1995,7 @@ XMLError XMLDocument::Parse( const char* p, size_t len )
if ( len == (size_t)(-1) ) { if ( len == (size_t)(-1) ) {
len = strlen( p ); len = strlen( p );
} }
TIXMLASSERT( _charBuffer == 0 );
_charBuffer = new char[ len+1 ]; _charBuffer = new char[ len+1 ];
memcpy( _charBuffer, p, len ); memcpy( _charBuffer, p, len );
_charBuffer[len] = 0; _charBuffer[len] = 0;