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:
@@ -458,13 +458,17 @@ private:
|
|||||||
{
|
{
|
||||||
if (newSize > m_size)
|
if (newSize > m_size)
|
||||||
{
|
{
|
||||||
void *dataOld = m_data;
|
void* const data = realloc(m_data, newSize + wxMemoryBufferData::DefBufSize);
|
||||||
m_data = realloc(m_data, newSize + wxMemoryBufferData::DefBufSize);
|
if ( !data )
|
||||||
if ( !m_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;
|
m_size = newSize + wxMemoryBufferData::DefBufSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user