summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-26 23:04:56 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-26 23:04:56 (GMT)
commit36577e4e8cf967083dea762407ba9d9d28de5b8a (patch)
treeb29158e419a563838c38deb008732636187fe20e
parent70c94e7896bc46c81e7b9648bde4745ce874f552 (diff)
downloadcpython-36577e4e8cf967083dea762407ba9d9d28de5b8a.zip
cpython-36577e4e8cf967083dea762407ba9d9d28de5b8a.tar.gz
cpython-36577e4e8cf967083dea762407ba9d9d28de5b8a.tar.bz2
Issue #15893: frozenmain.c now handles PyMem_Malloc() failure
-rw-r--r--Modules/python.c16
-rw-r--r--Python/frozenmain.c11
2 files changed, 19 insertions, 8 deletions
diff --git a/Modules/python.c b/Modules/python.c
index 8a548d3..f781d9a 100644
--- a/Modules/python.c
+++ b/Modules/python.c
@@ -18,11 +18,19 @@ wmain(int argc, wchar_t **argv)
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 @@ main(int argc, char **argv)
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++) {
diff --git a/Python/frozenmain.c b/Python/frozenmain.c
index f08caf2..98f46eb 100644
--- a/Python/frozenmain.c
+++ b/Python/frozenmain.c
@@ -20,9 +20,16 @@ Py_FrozenMain(int argc, char **argv)
int inspect = 0;
int unbuffered = 0;
char *oldloc;
- wchar_t **argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc);
+ wchar_t **argv_copy;
/* 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_copy2;
+
+ argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc);
+ argv_copy2 = PyMem_Malloc(sizeof(wchar_t*)*argc);
+ if (!argv_copy || !argv_copy2) {
+ fprintf(stderr, "out of memory\n");
+ return 1;
+ }
Py_FrozenFlag = 1; /* Suppress errors from getpath.c */