Prevent a crash with nested scopes, again caused by calling Py_DECREF when the pointer
is still present in the containing structure.
diff --git a/Objects/cellobject.c b/Objects/cellobject.c
index dc684d5..b72d43b 100644
--- a/Objects/cellobject.c
+++ b/Objects/cellobject.c
@@ -31,13 +31,15 @@
int
PyCell_Set(PyObject *op, PyObject *obj)
{
+ PyObject* oldobj;
if (!PyCell_Check(op)) {
PyErr_BadInternalCall();
return -1;
}
- Py_XDECREF(((PyCellObject*)op)->ob_ref);
+ oldobj = PyCell_GET(op);
Py_XINCREF(obj);
PyCell_SET(op, obj);
+ Py_XDECREF(oldobj);
return 0;
}