From: Vadim Zeitlin Date: Fri, 3 Mar 2006 23:06:54 +0000 (+0000) Subject: move the code freeing temporary argv array to wxEntry(HINSTANCE) overload to avoid... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/48733d474148267a7e1008b2bd019451d632ce17?ds=inline move the code freeing temporary argv array to wxEntry(HINSTANCE) overload to avoid doing it twice in some cases git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37789 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/app.cpp b/src/msw/app.cpp index af76477049..e071002e1b 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -503,17 +503,6 @@ wxApp::wxApp() wxApp::~wxApp() { - // our cmd line arguments are allocated inside wxEntry(HINSTANCE), they - // don't come from main(), so we have to free them - - while ( argc ) - { - // m_argv elements were allocated by wxStrdup() - free(argv[--argc]); - } - - // but m_argv itself -- using new[] - delete [] argv; } // ---------------------------------------------------------------------------- diff --git a/src/msw/main.cpp b/src/msw/main.cpp index 35f1ada5fc..712dc72347 100644 --- a/src/msw/main.cpp +++ b/src/msw/main.cpp @@ -27,6 +27,7 @@ #include "wx/event.h" #include "wx/app.h" #include "wx/cmdline.h" +#include "wx/scopeguard.h" #include "wx/msw/private.h" @@ -331,6 +332,20 @@ static bool wxIsUnicodeAvailable() // Windows-specific wxEntry // ---------------------------------------------------------------------------- +// helper function used to clean up in wxEntry() just below +// +// notice that argv elements are supposed to be allocated using malloc() while +// argv array itself is allocated with new +static void wxFreeArgs(int argc, wxChar **argv) +{ + for ( int i = 0; i < argc; i++ ) + { + free(argv[i]); + } + + delete [] argv; +} + WXDLLEXPORT int wxEntry(HINSTANCE hInstance, HINSTANCE WXUNUSED(hPrevInstance), wxCmdLineArgType WXUNUSED(pCmdLine), @@ -379,6 +394,8 @@ WXDLLEXPORT int wxEntry(HINSTANCE hInstance, // argv[] must be NULL-terminated argv[argc] = NULL; + wxON_BLOCK_EXIT2(wxFreeArgs, argc, argv); + return wxEntry(argc, argv); }