6
6
#include "pycore_dict.h" // _PyDict_GetItem_KnownHash()
7
7
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
8
8
#include "pycore_moduleobject.h" // _PyModule_GetState()
9
+ #include "pycore_object.h" // _Py_SetImmortalUntracked
9
10
#include "pycore_pyerrors.h" // _PyErr_ClearExcState()
10
11
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
11
12
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -3706,6 +3707,7 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop)
3706
3707
}
3707
3708
Py_DECREF (eager_iter );
3708
3709
TaskObj * head = state -> asyncio_tasks .head ;
3710
+ Py_INCREF (head );
3709
3711
assert (head != NULL );
3710
3712
assert (head -> prev == NULL );
3711
3713
TaskObj * tail = & state -> asyncio_tasks .tail ;
@@ -3714,10 +3716,11 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop)
3714
3716
if (add_one_task (state , tasks , (PyObject * )head , loop ) < 0 ) {
3715
3717
Py_DECREF (tasks );
3716
3718
Py_DECREF (loop );
3719
+ Py_DECREF (head );
3717
3720
return NULL ;
3718
3721
}
3719
- head = head -> next ;
3720
- assert (head != NULL );
3722
+ Py_INCREF ( head -> next ) ;
3723
+ Py_SETREF (head , head -> next );
3721
3724
}
3722
3725
PyObject * scheduled_iter = PyObject_GetIter (state -> non_asyncio_tasks );
3723
3726
if (scheduled_iter == NULL ) {
@@ -3944,6 +3947,8 @@ static int
3944
3947
module_exec (PyObject * mod )
3945
3948
{
3946
3949
asyncio_state * state = get_asyncio_state (mod );
3950
+ Py_SET_TYPE (& state -> asyncio_tasks .tail , state -> TaskType );
3951
+ _Py_SetImmortalUntracked ((PyObject * )& state -> asyncio_tasks .tail );
3947
3952
state -> asyncio_tasks .head = & state -> asyncio_tasks .tail ;
3948
3953
3949
3954
#define CREATE_TYPE (m , tp , spec , base ) \
0 commit comments