Backport r54757 - missing NULL checks.
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 0cd819c..b73a3f0 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -33,6 +33,8 @@
     PyBaseExceptionObject *self;
 
     self = (PyBaseExceptionObject *)type->tp_alloc(type, 0);
+    if (!self)
+        return NULL;
     /* the dict is created on the fly in PyObject_GenericSetAttr */
     self->message = self->dict = NULL;