Use wxScopedArray instead of raw new[]/delete[] and fix memory leak.
Don't leak memory in case of error when reading from the stream in BMP loading code. Closes #15789. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
5cd81ca598
commit
0a76afbe9c
@ -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
|
||||||
@ -578,9 +579,10 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
|
|||||||
// Reading the palette, if it exists:
|
// Reading the palette, if it exists:
|
||||||
if ( bpp < 16 && ncolors != 0 )
|
if ( bpp < 16 && ncolors != 0 )
|
||||||
{
|
{
|
||||||
unsigned char* r = new unsigned char[ncolors];
|
wxScopedArray<unsigned char>
|
||||||
unsigned char* g = new unsigned char[ncolors];
|
r(ncolors),
|
||||||
unsigned char* b = new unsigned char[ncolors];
|
g(ncolors),
|
||||||
|
b(ncolors);
|
||||||
for (int j = 0; j < ncolors; j++)
|
for (int j = 0; j < ncolors; j++)
|
||||||
{
|
{
|
||||||
if (hasPalette)
|
if (hasPalette)
|
||||||
@ -607,12 +609,8 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
|
|||||||
|
|
||||||
#if wxUSE_PALETTE
|
#if wxUSE_PALETTE
|
||||||
// Set the palette for the wxImage
|
// Set the palette for the wxImage
|
||||||
image->SetPalette(wxPalette(ncolors, r, g, b));
|
image->SetPalette(wxPalette(ncolors, r.get(), g.get(), b.get()));
|
||||||
#endif // wxUSE_PALETTE
|
#endif // wxUSE_PALETTE
|
||||||
|
|
||||||
delete[] r;
|
|
||||||
delete[] g;
|
|
||||||
delete[] b;
|
|
||||||
}
|
}
|
||||||
else if ( bpp == 16 || bpp == 32 )
|
else if ( bpp == 16 || bpp == 32 )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user