Skip to content

Commit

Permalink
Issue python#18408: type_new() and PyType_FromSpecWithBases() now rai…
Browse files Browse the repository at this point in the history
…se MemoryError

on memory allocation failure
  • Loading branch information
vstinner committed Jul 15, 2013
1 parent e699e5a commit 53510cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 53510cd

Please sign in to comment.