Skip to content

Commit dbcab73

Browse files
Clean up the created threadstate
This avoids a memory leak, as reported in #70.
1 parent 4c75587 commit dbcab73

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

context/_coroutine.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ static void *coroutine_wrapper(void *action_, void *arg_)
107107
Py_DECREF(arg);
108108

109109

110-
#if PY_VERSION_HEX < 0x30B0000
110+
#if PY_VERSION_HEX >= 0x30B0000
111+
new_threadstate = PyThreadState_Swap(thread_state);
112+
PyThreadState_Clear(new_threadstate);
113+
PyThreadState_Delete(new_threadstate);
114+
#else
111115
/* Some of the stuff we've initialised can leak through, so far I've only
112116
* seen exc_type still set at this point, but maybe other fields can also
113117
* leak. Avoid a memory leak by making sure we're not holding onto these.

0 commit comments

Comments
 (0)