]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45711: Use _PyErr_ClearExcState instead of setting only exc_value to NULL (GH...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Wed, 10 Nov 2021 16:57:14 +0000 (16:57 +0000)
committerGitHub <noreply@github.com>
Wed, 10 Nov 2021 16:57:14 +0000 (16:57 +0000)
Modules/_asynciomodule.c

index 8386a50d55826d34b707c4a3fd6cff05beef5558..df6644ba248ed7afdcfc61bb3da4cb7983839675 100644 (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;
 }