diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-08-20 12:18:25 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-08-20 12:18:25 (GMT) |
commit | 8fd544ffa926a479c8d80e245e3daf12197aa7a2 (patch) | |
tree | c0787daaaae9b9f707ae6fe1bd45ede1fb404796 /Objects | |
parent | 18bb330203bbff6a80343988efc12367b3be6686 (diff) | |
parent | a370fcf3b2211242c888558237557eb4895391d0 (diff) | |
download | cpython-8fd544ffa926a479c8d80e245e3daf12197aa7a2.zip cpython-8fd544ffa926a479c8d80e245e3daf12197aa7a2.tar.gz cpython-8fd544ffa926a479c8d80e245e3daf12197aa7a2.tar.bz2 |
Issue #12791: Break reference cycles early when a generator exits with an exception.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/genobject.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c index cb2980c..43d0335 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; } |