Handle allocation failures gracefully. Found with failmalloc.
Many (all?) of these could be backported.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 2046972..6b48430 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3260,6 +3260,8 @@
if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) {
if (type->tp_doc != NULL) {
PyObject *doc = PyString_FromString(type->tp_doc);
+ if (doc == NULL)
+ goto error;
PyDict_SetItemString(type->tp_dict, "__doc__", doc);
Py_DECREF(doc);
} else {
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 08fdb3f..096dfc6 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -7918,6 +7918,9 @@
unicode_freelist = NULL;
unicode_freelist_size = 0;
unicode_empty = _PyUnicode_New(0);
+ if (!unicode_empty)
+ return;
+
strcpy(unicode_default_encoding, "ascii");
for (i = 0; i < 256; i++)
unicode_latin1[i] = NULL;