Slightly improve out of memory handling in wxMemoryBuffer.

Reset not only m_data but also m_size and m_len to 0 if we run out of memory.

Closes #4500.
This commit is contained in:
Vadim Zeitlin 2015-03-13 16:58:37 +01:00
parent 5a44f8ea70
commit 6b84e6e1b9

View File

@ -458,13 +458,17 @@ private:
{
if (newSize > m_size)
{
void *dataOld = m_data;
m_data = realloc(m_data, newSize + wxMemoryBufferData::DefBufSize);
if ( !m_data )
void* const data = realloc(m_data, newSize + wxMemoryBufferData::DefBufSize);
if ( !data )
{
free(dataOld);
// It's better to crash immediately dereferencing a null
// pointer in the function calling us than overflowing the
// buffer which couldn't be made big enough.
free(release());
return;
}
m_data = data;
m_size = newSize + wxMemoryBufferData::DefBufSize;
}
}