]> granicus.if.org Git - python/commitdiff
Issue #18520: PyErr_NoMemory() now fails with a fatal error if it is called
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 22 Jul 2013 20:28:37 +0000 (22:28 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 22 Jul 2013 20:28:37 +0000 (22:28 +0200)
before PyExc_MemoryError has been initialized by _PyExc_Init()

Python/errors.c

index b0f8b189392fab51e7001b86927ce42d3b5e0564..8c0c01849c357c4831480a1b7a9f1ca920933dc3 100644 (file)
@@ -380,6 +380,12 @@ PyErr_BadArgument(void)
 PyObject *
 PyErr_NoMemory(void)
 {
+    if (Py_TYPE(PyExc_MemoryError) == NULL) {
+        /* PyErr_NoMemory() has been called before PyExc_MemoryError has been
+           initialized by _PyExc_Init() */
+        Py_FatalError("Out of memory and PyExc_MemoryError is not "
+                      "initialized yet");
+    }
     PyErr_SetNone(PyExc_MemoryError);
     return NULL;
 }