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/branches/WX_3_0_BRANCH@76124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include "wx/wfstream.h"
|
#include "wx/wfstream.h"
|
||||||
#include "wx/quantize.h"
|
#include "wx/quantize.h"
|
||||||
#include "wx/scopeguard.h"
|
#include "wx/scopeguard.h"
|
||||||
|
#include "wx/scopedarray.h"
|
||||||
#include "wx/anidecod.h"
|
#include "wx/anidecod.h"
|
||||||
|
|
||||||
// For memcpy
|
// For memcpy
|
||||||
@@ -1425,8 +1426,8 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream,
|
|||||||
wxUint16 nType = wxUINT16_SWAP_ON_BE(IconDir.idType);
|
wxUint16 nType = wxUINT16_SWAP_ON_BE(IconDir.idType);
|
||||||
|
|
||||||
// loop round the icons and choose the best one:
|
// loop round the icons and choose the best one:
|
||||||
ICONDIRENTRY *pIconDirEntry = new ICONDIRENTRY[nIcons];
|
wxScopedArray<ICONDIRENTRY> pIconDirEntry(nIcons);
|
||||||
ICONDIRENTRY *pCurrentEntry = pIconDirEntry;
|
ICONDIRENTRY *pCurrentEntry = pIconDirEntry.get();
|
||||||
int wMax = 0;
|
int wMax = 0;
|
||||||
int colmax = 0;
|
int colmax = 0;
|
||||||
int iSel = wxNOT_FOUND;
|
int iSel = wxNOT_FOUND;
|
||||||
@@ -1473,7 +1474,7 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// seek to selected icon:
|
// seek to selected icon:
|
||||||
pCurrentEntry = pIconDirEntry + iSel;
|
pCurrentEntry = pIconDirEntry.get() + iSel;
|
||||||
|
|
||||||
// NOTE: seeking a positive amount in wxFromCurrent mode allows us to
|
// NOTE: seeking a positive amount in wxFromCurrent mode allows us to
|
||||||
// load even non-seekable streams (see wxInputStream::SeekI docs)!
|
// load even non-seekable streams (see wxInputStream::SeekI docs)!
|
||||||
@@ -1491,8 +1492,6 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] pIconDirEntry;
|
|
||||||
|
|
||||||
return bResult;
|
return bResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user