From 563f41c68691a5244f3eb6020a3fe7742e2684e2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Feb 2014 00:51:49 +0000 Subject: [PATCH] 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 --- src/osx/core/display.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/osx/core/display.cpp b/src/osx/core/display.cpp index b1961bc92e..ac512268c4 100644 --- a/src/osx/core/display.cpp +++ b/src/osx/core/display.cpp @@ -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 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]); } // ============================================================================