Skip to content

Commit 3944e9b

Browse files
[3.14] pythongh-140431: Fix GC crash due to partially initialized coroutines (pythongh-140470) (pythongh-140504)
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. (cherry picked from commit 574405c) Co-authored-by: Sam Gross <[email protected]>
1 parent 564bb00 commit 3944e9b

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
@@ -922,6 +922,7 @@ make_gen(PyTypeObject *type, PyFunctionObject *func)
922922
gen->gi_weakreflist = NULL;
923923
gen->gi_exc_state.exc_value = NULL;
924924
gen->gi_exc_state.previous_item = NULL;
925+
gen->gi_iframe.f_executable = PyStackRef_None;
925926
assert(func->func_name != NULL);
926927
gen->gi_name = Py_NewRef(func->func_name);
927928
assert(func->func_qualname != NULL);

0 commit comments

Comments
 (0)