diff Modules/python.c @ 84857:ab8121466785 3.3

Issue #15893: frozenmain.c now handles PyMem_Malloc() failure
author Victor Stinner <victor.stinner@gmail.com>
date Sat, 27 Jul 2013 01:04:56 +0200
parents c02656962b9c
children 386ab2c12301
line wrap: on
line diff
--- a/Modules/python.c	Sat Jul 27 00:33:13 2013 +0200
+++ b/Modules/python.c	Sat Jul 27 01:04:56 2013 +0200
@@ -18,11 +18,19 @@
 int
 main(int argc, char **argv)
 {
-    wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
+    wchar_t **argv_copy;
     /* We need a second copy, as Python might modify the first one. */
-    wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
+    wchar_t **argv_copy2;
     int i, res;
     char *oldloc;
+
+    argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
+    argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
+    if (!argv_copy || !argv_copy2) {
+        fprintf(stderr, "out of memory\n");
+        return 1;
+    }
+
     /* 754 requires that FP exceptions run in "no stop" mode by default,
      * and until C vendors implement C99's ways to control FP exceptions,
      * Python requires non-stop mode.  Alas, some platforms enable FP
@@ -34,10 +42,6 @@
     m = fpgetmask();
     fpsetmask(m & ~FP_X_OFL);
 #endif
-    if (!argv_copy || !argv_copy2) {
-        fprintf(stderr, "out of memory\n");
-        return 1;
-    }
     oldloc = strdup(setlocale(LC_ALL, NULL));
     setlocale(LC_ALL, "");
     for (i = 0; i < argc; i++) {