diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-13-06-23-56.gh-issue-159294.9LTsNA.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-13-06-23-56.gh-issue-159294.9LTsNA.rst new file mode 100644 index 00000000000000..9504f1f753cbec --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-13-06-23-56.gh-issue-159294.9LTsNA.rst @@ -0,0 +1,3 @@ +Fix a crash in a debug build when creating an :exc:`ExceptionGroup` or +:exc:`BaseExceptionGroup` fails with :exc:`MemoryError`. Patch by Christian +Aurich Zanettini Martins. diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 67ba540b552a58..b3473751684f0f 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -998,11 +998,11 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds) */ cls = (PyTypeObject*)PyExc_BaseExceptionGroup; } - PyBaseExceptionGroupObject *self = - PyBaseExceptionGroupObject_CAST(BaseException_new(cls, args, kwds)); - if (!self) { + PyObject *op = BaseException_new(cls, args, kwds); + if (!op) { goto error; } + PyBaseExceptionGroupObject *self = PyBaseExceptionGroupObject_CAST(op); self->msg = Py_NewRef(message); self->excs = exceptions;