bpo-45711: Use _PyErr_ClearExcState instead of setting only exc_value to NULL (GH-29404)

This commit is contained in:
Irit Katriel 2021-11-10 16:57:14 +00:00 committed by GitHub
parent 76d14fac72
commit 05fbd60147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1371,10 +1371,15 @@ _asyncio_Future__make_cancelled_error_impl(FutureObj *self)
{
PyObject *exc = create_cancelled_error(self->fut_cancel_msg);
_PyErr_StackItem *exc_state = &self->fut_cancelled_exc_state;
/* Transfer ownership of exc_value from exc_state to exc since we are
done with it. */
PyException_SetContext(exc, exc_state->exc_value);
exc_state->exc_value = NULL;
if (exc_state->exc_value) {
PyException_SetContext(exc, Py_NewRef(exc_state->exc_value));
_PyErr_ClearExcState(exc_state);
}
else {
assert(exc_state->exc_type == NULL);
assert(exc_state->exc_traceback == NULL);
}
return exc;
}