mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Issue #12791: Break reference cycles early when a generator exits with an exception.
This commit is contained in:
commit
8fd544ffa9
3 changed files with 76 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue