summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/genobject.c5
2 files changed, 7 insertions, 1 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 01bef3c1a5..596f0d0485 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,9 @@ Core and Builtins
- Issue #27506: Support passing the bytes/bytearray.translate() "delete"
argument by keyword.
+- Issue #27812: Properly clear out a generator's frame's backreference to the
+ generator to prevent crashes in frame.clear().
+
- Issue #27811: Fix a crash when a coroutine that has not been awaited is
finalized with warnings-as-errors enabled.
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 7492bdcb28..f4c5b47b8a 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -71,7 +71,10 @@ gen_dealloc(PyGenObject *gen)
return; /* resurrected. :( */
_PyObject_GC_UNTRACK(self);
- Py_CLEAR(gen->gi_frame);
+ if (gen->gi_frame != NULL) {
+ gen->gi_frame->f_gen = NULL;
+ Py_CLEAR(gen->gi_frame);
+ }
Py_CLEAR(gen->gi_code);
Py_CLEAR(gen->gi_name);
Py_CLEAR(gen->gi_qualname);