From 18c30a29f86dc41f96a572b6ec3f7bd6824f6e6a Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Sun, 10 May 2015 15:09:46 -0400 Subject: [PATCH] Issue #22906: Do incref before SetCause/SetContext --- Objects/genobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/genobject.c b/Objects/genobject.c index 149e545ec06..82b629cfea8 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -149,9 +149,9 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc) "generator raised StopIteration"); PyErr_Fetch(&exc, &val2, &tb); PyErr_NormalizeException(&exc, &val2, &tb); + Py_INCREF(val); PyException_SetCause(val2, val); PyException_SetContext(val2, val); - Py_INCREF(val); PyErr_Restore(exc, val2, tb); } }