From f5033eec653682a331492cb861e60d71e53935b5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Feb 2014 00:51:41 +0000 Subject: [PATCH] No real changes, just use smart pointers in GIF decoding code. Use wxScopedArray to make the code much shorter and guarantee that it doesn't leak memory. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75953 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/gifdecod.cpp | 44 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/src/common/gifdecod.cpp b/src/common/gifdecod.cpp index b478b31622..bea6addc38 100644 --- a/src/common/gifdecod.cpp +++ b/src/common/gifdecod.cpp @@ -25,6 +25,7 @@ #include #include #include "wx/gifdecod.h" +#include "wx/scopedarray.h" #include "wx/scopedptr.h" #include "wx/scopeguard.h" @@ -317,26 +318,18 @@ wxGIFErrorCode wxGIFDecoder::dgif(wxInputStream& stream, GIFImage *img, int interl, int bits) { static const int allocSize = 4096 + 1; - int *ab_prefix = new int[allocSize]; // alphabet (prefixes) - if (ab_prefix == NULL) - { - return wxGIF_MEMERR; - } - int *ab_tail = new int[allocSize]; // alphabet (tails) - if (ab_tail == NULL) - { - delete[] ab_prefix; + wxScopedArray ab_prefix(allocSize); // alphabet (prefixes) + if ( !ab_prefix ) return wxGIF_MEMERR; - } - int *stack = new int[allocSize]; // decompression stack - if (stack == NULL) - { - delete[] ab_prefix; - delete[] ab_tail; + wxScopedArray ab_tail(allocSize); // alphabet (tails) + if ( !ab_tail ) + return wxGIF_MEMERR; + + wxScopedArray stack(allocSize); // decompression stack + if ( !stack ) return wxGIF_MEMERR; - } int ab_clr; // clear code int ab_fin; // end of info code @@ -406,21 +399,11 @@ wxGIFDecoder::dgif(wxInputStream& stream, GIFImage *img, int interl, int bits) // GIF files, the allocSize of 4096+1 is enough. This // will only happen with badly formed GIFs. if (pos >= allocSize) - { - delete[] ab_prefix; - delete[] ab_tail; - delete[] stack; return wxGIF_INVFORMAT; - } } if (pos >= allocSize) - { - delete[] ab_prefix; - delete[] ab_tail; - delete[] stack; return wxGIF_INVFORMAT; - } stack[pos] = code; // push last code into the stack abcabca = code; // save for special case @@ -433,12 +416,7 @@ wxGIFDecoder::dgif(wxInputStream& stream, GIFImage *img, int interl, int bits) // to reset it. This checks whether we really got it, otherwise // the GIF is damaged. if (ab_free > ab_max) - { - delete[] ab_prefix; - delete[] ab_tail; - delete[] stack; return wxGIF_INVFORMAT; - } // This assert seems unnecessary since the condition above // eliminates the only case in which it went false. But I really @@ -578,10 +556,6 @@ as an End of Information itself) } while (code != ab_fin); - delete [] ab_prefix ; - delete [] ab_tail ; - delete [] stack ; - return wxGIF_OK; }