diff -r 1704deb7e6d7 Python/frozenmain.c --- a/Python/frozenmain.c Sun Sep 16 00:13:10 2012 +0200 +++ b/Python/frozenmain.c Sat Sep 15 21:40:48 2012 -0700 @@ -20,12 +20,28 @@ int inspect = 0; int unbuffered = 0; char *oldloc; - wchar_t **argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc); - /* We need a second copies, as Python might modify the first one. */ - wchar_t **argv_copy2 = PyMem_Malloc(sizeof(wchar_t*)*argc); + wchar_t **argv_copy = NULL; + /* We need a second copy, as Python might modify the first one. */ + wchar_t **argv_copy2 = NULL; + const size_t argv_size = sizeof(wchar_t*) * argc; Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ + argv_copy = PyMem_Malloc(argv_size); + if (!argv_copy) { + fprintf(stderr, "out of memory\n"); + sts = 1; + goto done; + } + + argv_copy2 = PyMem_Malloc(argv_size); + if (!argv_copy2) { + fprintf(stderr, "out of memory\n"); + sts = 1; + goto done; + } + memset (argv_copy2, 0, argv_size); + if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') inspect = 1; if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') @@ -37,11 +53,6 @@ setbuf(stderr, (char *)NULL); } - if (!argv_copy) { - fprintf(stderr, "out of memory\n"); - return 1; - } - oldloc = setlocale(LC_ALL, NULL); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { @@ -53,18 +64,21 @@ size_t count; if (argsize == (size_t)-1) { fprintf(stderr, "Could not convert argument %d to string\n", i); - return 1; + sts = 1; + goto done; } argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t)); argv_copy2[i] = argv_copy[i]; if (!argv_copy[i]) { fprintf(stderr, "out of memory\n"); - return 1; + sts = 1; + goto done; } count = mbstowcs(argv_copy[i], argv[i], argsize+1); if (count == (size_t)-1) { fprintf(stderr, "Could not convert argument %d to string\n", i); - return 1; + sts = 1; + goto done; } } setlocale(LC_ALL, oldloc); @@ -100,7 +114,11 @@ #ifdef MS_WINDOWS PyWinFreeze_ExeTerm(); #endif + Py_Finalize(); + +done: + for (i = 0; i < argc; i++) { PyMem_Free(argv_copy2[i]); }