summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-08-20 12:15:03 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-08-20 12:15:03 (GMT)
commita370fcf3b2211242c888558237557eb4895391d0 (patch)
tree4c52a9237332bc7b3e1e9d0eba8e84c878acd210 /Objects
parent0c17d0d96e9684e29a731227452355da79b14b5b (diff)
downloadcpython-a370fcf3b2211242c888558237557eb4895391d0.zip
cpython-a370fcf3b2211242c888558237557eb4895391d0.tar.gz
cpython-a370fcf3b2211242c888558237557eb4895391d0.tar.bz2
Issue #12791: Break reference cycles early when a generator exits with an exception.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/genobject.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 3fa1b4e..01cd44a 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -100,6 +100,17 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc)
if (!result || f->f_stacktop == NULL) {
/* generator can't be rerun, so release the frame */
+ /* first clean reference cycle through stored exception traceback */
+ PyObject *t, *v, *tb;
+ t = f->f_exc_type;
+ v = f->f_exc_value;
+ tb = f->f_exc_traceback;
+ f->f_exc_type = NULL;
+ f->f_exc_value = NULL;
+ f->f_exc_traceback = NULL;
+ Py_XDECREF(t);
+ Py_XDECREF(v);
+ Py_XDECREF(tb);
Py_DECREF(f);
gen->gi_frame = NULL;
}