Skip to content

Commit 56eefee

Browse files
committed
Ensure that the exceptions copy in BaseExceptionGroup repr is freed
1 parent f93ae8f commit 56eefee

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Objects/exceptions.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,12 +1073,17 @@ BaseExceptionGroup_repr(PyObject *op)
10731073
PyObject* excs_orig = PyTuple_GET_ITEM(self->args, 1);
10741074
if (PyList_Check(excs_orig)) {
10751075
excs_orig = PySequence_List(self->excs);
1076+
} else {
1077+
Py_INCREF(excs_orig);
10761078
}
10771079

10781080
const char *name = _PyType_Name(Py_TYPE(self));
1079-
return PyUnicode_FromFormat(
1081+
PyObject *repr = PyUnicode_FromFormat(
10801082
"%s(%R, %R)", name,
10811083
self->msg, excs_orig);
1084+
1085+
Py_DECREF(excs_orig);
1086+
return repr;
10821087
}
10831088

10841089
/*[clinic input]

0 commit comments

Comments
 (0)