Skip to content

Commit bdddb11

Browse files
committed
clear out f_gen during generator finalization (closes #27812)
Patch from Armin Rigo.
1 parent 80109d3 commit bdddb11

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27812: Properly clear out a generator's frame's backreference to the
14+
generator to prevent crashes in frame.clear().
15+
1316
- Issue #27811: Fix a crash when a coroutine that has not been awaited is
1417
finalized with warnings-as-errors enabled.
1518

Objects/genobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ gen_dealloc(PyGenObject *gen)
7171
return; /* resurrected. :( */
7272

7373
_PyObject_GC_UNTRACK(self);
74-
Py_CLEAR(gen->gi_frame);
74+
if (gen->gi_frame != NULL) {
75+
gen->gi_frame->f_gen = NULL;
76+
Py_CLEAR(gen->gi_frame);
77+
}
7578
Py_CLEAR(gen->gi_code);
7679
Py_CLEAR(gen->gi_name);
7780
Py_CLEAR(gen->gi_qualname);

0 commit comments

Comments
 (0)