Fix crash in wxCharBuffer if memory allocation fails.

Handle memory allocation failure gracefully in wxCharTypeBuffer ctor.

Closes #15616.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75092 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-10-28 15:04:10 +00:00
parent b8f637041f
commit 3b636935b3
2 changed files with 24 additions and 3 deletions

View File

@@ -567,6 +567,14 @@ Major new features in this release
was added. was added.
3.0.0: (released 2013-11-xx)
----------------------------
All:
- Fix crash if wxCharBuffer fails to allocate the requested amount of memory.
3.0-RC2: (released 2013-10-28) 3.0-RC2: (released 2013-10-28)
------------------------------ ------------------------------

View File

@@ -268,9 +268,22 @@ public:
wxCharTypeBuffer(size_t len) wxCharTypeBuffer(size_t len)
{ {
this->m_data = CharType* const str = (CharType *)malloc((len + 1)*sizeof(CharType));
new Data((CharType *)malloc((len + 1)*sizeof(CharType)), len); if ( str )
this->m_data->Get()[len] = (CharType)0; {
str[len] = (CharType)0;
// There is a potential memory leak here if new throws because it
// fails to allocate Data, we ought to use new(nothrow) here, but
// this might fail to compile under some platforms so until this
// can be fully tested, just live with this (rather unlikely, as
// Data is a small object) potential leak.
this->m_data = new Data(str, len);
}
else
{
this->m_data = this->GetNullData();
}
} }
wxCharTypeBuffer(const wxCharTypeBuffer& src) wxCharTypeBuffer(const wxCharTypeBuffer& src)