summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-15 19:34:20 +0200
committerVictor Stinner <victor.stinner@gmail.com>2013-07-15 19:34:20 +0200
commit53510cda598125a82b643af6eca46dd0f26099b3 (patch)
tree02c42f4374a70fd2286ea7890070b677c59c77ca
parente699e5a21869d8ced1726518044faae45dd22b9c (diff)
downloadcpython-git-53510cda598125a82b643af6eca46dd0f26099b3.tar.gz
Issue #18408: type_new() and PyType_FromSpecWithBases() now raise MemoryError
on memory allocation failure
-rw-r--r--Objects/typeobject.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 560c929b73..9b69021299 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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;
}