From ef5571c62ae14526f2234326bef1c0330d75b06e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Aug 2008 00:32:12 +0000 Subject: [PATCH 1/1] no real changes, just some cleanup: use wxON_BLOCK_EXIT instead of littering the code with delete[] statements; don't use identifiers starting with underscore git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54943 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/imagbmp.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index fc67b77313..4380d0b2d1 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -33,6 +33,7 @@ #include "wx/filefn.h" #include "wx/wfstream.h" #include "wx/quantize.h" +#include "wx/scopeguard.h" #include "wx/anidecod.h" // For memcpy @@ -469,10 +470,12 @@ bool wxBMPHandler::SaveDib(wxImage *image, } -typedef struct +struct BMPPalette { + static void Free(BMPPalette* pal) { delete [] pal; } + unsigned char r, g, b; -} _cmap; +}; bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height, int bpp, int ncolors, int comp, @@ -488,11 +491,11 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height, wxUint16 aWord; // allocate space for palette if needed: - _cmap *cmap; + BMPPalette *cmap; if ( bpp < 16 ) { - cmap = new _cmap[ncolors]; + cmap = new BMPPalette[ncolors]; if ( !cmap ) { if (verbose) @@ -500,8 +503,12 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height, return false; } } - else + else // no palette + { cmap = NULL; + } + + wxON_BLOCK_EXIT1(&BMPPalette::Free, cmap); // destroy existing here instead of: image->Destroy(); @@ -513,7 +520,6 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height, { if ( verbose ) wxLogError( _("BMP: Couldn't allocate memory.") ); - delete[] cmap; return false; } @@ -527,7 +533,6 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height, { if ( verbose ) wxLogError(_("BMP: Couldn't allocate memory.")); - delete[] cmap; return false; } } @@ -879,8 +884,6 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height, } } - delete[] cmap; - image->SetMask(false); const wxStreamError err = stream.GetLastError(); -- 2.45.2