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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user