[Python-checkins] Fix refleaks in PyErr_SetHandledException (GH-91627)
sweeneyde
webhook-mailer at python.org
Sun Apr 17 02:52:57 EDT 2022
https://github.com/python/cpython/commit/3289209716011b21128f45de69f4a8e9d376c78e
commit: 3289209716011b21128f45de69f4a8e9d376c78e
branch: main
author: Dennis Sweeney <36520290+sweeneyde at users.noreply.github.com>
committer: sweeneyde <36520290+sweeneyde at users.noreply.github.com>
date: 2022-04-17T02:52:53-04:00
summary:
Fix refleaks in PyErr_SetHandledException (GH-91627)
files:
M Python/errors.c
diff --git a/Python/errors.c b/Python/errors.c
index ce7785855b8e5..3eb8a5ef04d28 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);
More information about the Python-checkins
mailing list