Skip to content

Commit 574405c

Browse files
authored
gh-140431: Fix GC crash due to partially initialized coroutines (gh-140470)
The `make_gen()` function creates and tracks generator/coro objects, but doesn't fully initialize all the fields. At a minimum, we need to initialize all the fields that may be accessed by gen_traverse because the call to `compute_cr_origin()` can trigger a GC.
1 parent 4d08494 commit 574405c

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a crash in Python's :term:`garbage collector <garbage collection>` due to
2+
partially initialized :term:`coroutine` objects when coroutine origin tracking
3+
depth is enabled (:func:`sys.set_coroutine_origin_tracking_depth`).

Objects/genobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ make_gen(PyTypeObject *type, PyFunctionObject *func)
932932
gen->gi_weakreflist = NULL;
933933
gen->gi_exc_state.exc_value = NULL;
934934
gen->gi_exc_state.previous_item = NULL;
935+
gen->gi_iframe.f_executable = PyStackRef_None;
935936
assert(func->func_name != NULL);
936937
gen->gi_name = Py_NewRef(func->func_name);
937938
assert(func->func_qualname != NULL);

0 commit comments

Comments
 (0)