Fix memory leak on error return in wxOSX wxDisplay code.

Use wxScopedArray to ensure that memory is freed, even if wxCHECK_MSG()
condition fails.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75956 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-02-21 00:51:49 +00:00
parent 3dd1d4d915
commit 563f41c686

View File

@ -34,6 +34,7 @@
#endif
#include "wx/display_impl.h"
#include "wx/scopedarray.h"
#include "wx/osx/private.h"
#if wxOSX_USE_COCOA_OR_CARBON
@ -175,18 +176,14 @@ int wxDisplayFactoryMacOSX::GetFromPoint(const wxPoint& p)
wxDisplayImpl *wxDisplayFactoryMacOSX::CreateDisplay(unsigned n)
{
CGDisplayCount theCount = GetCount();
CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount];
wxScopedArray<CGDirectDisplayID> theIDs(theCount);
CGDisplayErr err = wxOSXGetDisplayList(theCount, theIDs, &theCount);
wxCHECK_MSG( err == CGDisplayNoErr, NULL, "wxOSXGetDisplayList() failed" );
wxASSERT( n < theCount );
wxDisplayImplMacOSX *display = new wxDisplayImplMacOSX(n, theIDs[n]);
delete [] theIDs;
return display;
return new wxDisplayImplMacOSX(n, theIDs[n]);
}
// ============================================================================