From d8090867aa17f4246461b88f3fc811184f77a47a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 12 Mar 2014 23:03:55 +0000 Subject: [PATCH] Fix possible memory leak in wxICOHandler loading code. Use wxScopedArray<> instead of a raw pointer to ensure that the memory is always freed, even in case of error return. See #15918. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76128 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/imagbmp.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index 20cdf50c17..2675d8084f 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -1419,8 +1419,8 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream, wxUint16 nType = wxUINT16_SWAP_ON_BE(IconDir.idType); // loop round the icons and choose the best one: - ICONDIRENTRY *pIconDirEntry = new ICONDIRENTRY[nIcons]; - ICONDIRENTRY *pCurrentEntry = pIconDirEntry; + wxScopedArray pIconDirEntry(nIcons); + ICONDIRENTRY *pCurrentEntry = pIconDirEntry.get(); int wMax = 0; int colmax = 0; int iSel = wxNOT_FOUND; @@ -1467,7 +1467,7 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream, else { // seek to selected icon: - pCurrentEntry = pIconDirEntry + iSel; + pCurrentEntry = pIconDirEntry.get() + iSel; // NOTE: seeking a positive amount in wxFromCurrent mode allows us to // load even non-seekable streams (see wxInputStream::SeekI docs)! @@ -1485,8 +1485,6 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream, } } - delete [] pIconDirEntry; - return bResult; }