]> granicus.if.org Git - python/commitdiff
Issue #18408: type_new() and PyType_FromSpecWithBases() now raise MemoryError
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 15 Jul 2013 17:34:20 +0000 (19:34 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 15 Jul 2013 17:34:20 +0000 (19:34 +0200)
on memory allocation failure

Objects/typeobject.c

index 560c929b73da909f800d6be31317e5a36fa61c17..9b6902129975313f1adb5f2c63d7c6b6d43d1681 100644 (file)
@@ -2292,8 +2292,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
             /* Silently truncate the docstring if it contains null bytes. */
             len = strlen(doc_str);
             tp_doc = (char *)PyObject_MALLOC(len + 1);
-            if (tp_doc == NULL)
+            if (tp_doc == NULL) {
+                PyErr_NoMemory();
                 goto error;
+            }
             memcpy(tp_doc, doc_str, len + 1);
             type->tp_doc = tp_doc;
         }
@@ -2496,8 +2498,10 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
         if (slot->slot == Py_tp_doc) {
             size_t len = strlen(slot->pfunc)+1;
             char *tp_doc = PyObject_MALLOC(len);
-            if (tp_doc == NULL)
+            if (tp_doc == NULL) {
+                PyErr_NoMemory();
                 goto fail;
+            }
             memcpy(tp_doc, slot->pfunc, len);
             type->tp_doc = tp_doc;
         }