From: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> Date: Sun, 17 Apr 2022 06:52:53 +0000 (-0400) Subject: Fix refleaks in PyErr_SetHandledException (GH-91627) X-Git-Tag: v3.11.0b1~335 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3289209716011b21128f45de69f4a8e9d376c78e;p=thirdparty%2FPython%2Fcpython.git Fix refleaks in PyErr_SetHandledException (GH-91627) --- diff --git a/Python/errors.c b/Python/errors.c index ce7785855b8e..3eb8a5ef04d2 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -520,9 +520,7 @@ PyErr_GetHandledException(void) void _PyErr_SetHandledException(PyThreadState *tstate, PyObject *exc) { - PyObject *oldexc = tstate->exc_info->exc_value; - tstate->exc_info->exc_value = Py_XNewRef(exc); - Py_XDECREF(oldexc); + Py_XSETREF(tstate->exc_info->exc_value, Py_XNewRef(exc)); } void @@ -543,6 +541,7 @@ void PyErr_SetExcInfo(PyObject *type, PyObject *value, PyObject *traceback) { PyErr_SetHandledException(value); + Py_XDECREF(value); /* These args are no longer used, but we still need to steal a ref */ Py_XDECREF(type); Py_XDECREF(traceback);