]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix refleaks in PyErr_SetHandledException (GH-91627)
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Sun, 17 Apr 2022 06:52:53 +0000 (02:52 -0400)
committerGitHub <noreply@github.com>
Sun, 17 Apr 2022 06:52:53 +0000 (02:52 -0400)
Python/errors.c

index ce7785855b8e548b892b2efb165c84094c689e96..3eb8a5ef04d284df352360430b91108d15f74c46 100644 (file)
@@ -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);