Skip to content

Commit 05fbd60

Browse files
authored
bpo-45711: Use _PyErr_ClearExcState instead of setting only exc_value to NULL (GH-29404)
1 parent 76d14fa commit 05fbd60

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Modules/_asynciomodule.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -1371,10 +1371,15 @@ _asyncio_Future__make_cancelled_error_impl(FutureObj *self)
13711371
{
13721372
PyObject *exc = create_cancelled_error(self->fut_cancel_msg);
13731373
_PyErr_StackItem *exc_state = &self->fut_cancelled_exc_state;
1374-
/* Transfer ownership of exc_value from exc_state to exc since we are
1375-
done with it. */
1376-
PyException_SetContext(exc, exc_state->exc_value);
1377-
exc_state->exc_value = NULL;
1374+
1375+
if (exc_state->exc_value) {
1376+
PyException_SetContext(exc, Py_NewRef(exc_state->exc_value));
1377+
_PyErr_ClearExcState(exc_state);
1378+
}
1379+
else {
1380+
assert(exc_state->exc_type == NULL);
1381+
assert(exc_state->exc_traceback == NULL);
1382+
}
13781383

13791384
return exc;
13801385
}

0 commit comments

Comments
 (0)