mirror of
https://github.com/python/cpython.git
synced 2026-03-30 16:41:06 +00:00
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.
This commit is contained in:
parent
4d0849426f
commit
574405c19e
2 changed files with 4 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
Fix a crash in Python's :term:`garbage collector <garbage collection>` due to
|
||||
partially initialized :term:`coroutine` objects when coroutine origin tracking
|
||||
depth is enabled (:func:`sys.set_coroutine_origin_tracking_depth`).
|
||||
|
|
@ -932,6 +932,7 @@ make_gen(PyTypeObject *type, PyFunctionObject *func)
|
|||
gen->gi_weakreflist = NULL;
|
||||
gen->gi_exc_state.exc_value = NULL;
|
||||
gen->gi_exc_state.previous_item = NULL;
|
||||
gen->gi_iframe.f_executable = PyStackRef_None;
|
||||
assert(func->func_name != NULL);
|
||||
gen->gi_name = Py_NewRef(func->func_name);
|
||||
assert(func->func_qualname != NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue