Skip to content

Commit 9211d01

Browse files
committed
Handle error on __repr__ for exceptions sequence passed to ExceptionGroup()
1 parent ce39eec commit 9211d01

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Objects/exceptions.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,13 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
909909
/* Save initial exceptions sequence as a string incase sequence is mutated */
910910
if (!PyList_Check(exceptions) && !PyTuple_Check(exceptions)) {
911911
exceptions_str = PyObject_Repr(exceptions);
912+
if (exceptions_str == NULL) {
913+
/* We don't hold a reference to exceptions, so clear it before
914+
* attempting a decref in the cleanup.
915+
*/
916+
exceptions = NULL;
917+
goto error;
918+
}
912919
}
913920

914921
exceptions = PySequence_Tuple(exceptions);
@@ -997,7 +1004,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
9971004
self->excs_str = exceptions_str;
9981005
return (PyObject*)self;
9991006
error:
1000-
Py_DECREF(exceptions);
1007+
Py_XDECREF(exceptions);
10011008
Py_XDECREF(exceptions_str);
10021009
return NULL;
10031010
}

0 commit comments

Comments
 (0)