diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-01 14:12:34 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-01 14:12:34 (GMT) |
commit | 14eefe353e3f251bce0bc7ed3415f78c17174d94 (patch) | |
tree | e809c04903624a9caf6a3a8f1b8024b73423f625 /Objects | |
parent | 964ec8b2f3bb893ad34d874e55a180a90330bde2 (diff) | |
download | cpython-14eefe353e3f251bce0bc7ed3415f78c17174d94.zip cpython-14eefe353e3f251bce0bc7ed3415f78c17174d94.tar.gz cpython-14eefe353e3f251bce0bc7ed3415f78c17174d94.tar.bz2 |
Issue #25395: Fixed crash when highly nested OrderedDict structures were
garbage collected.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/odictobject.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 4bdd45a..a03e995 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1431,17 +1431,28 @@ static PyMemberDef odict_members[] = { static void odict_dealloc(PyODictObject *self) { + PyThreadState *tstate = PyThreadState_GET(); + PyObject_GC_UnTrack(self); - Py_TRASHCAN_SAFE_BEGIN(self); + Py_TRASHCAN_SAFE_BEGIN(self) + Py_XDECREF(self->od_inst_dict); if (self->od_weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *)self); _odict_clear_nodes(self); - Py_TRASHCAN_SAFE_END(self); - /* must be last */ + /* Call the base tp_dealloc(). Since it too uses the trashcan mechanism, + * temporarily decrement trash_delete_nesting to prevent triggering it + * and putting the partially deallocated object on the trashcan's + * to-be-deleted-later list. + */ + --tstate->trash_delete_nesting; + assert(_tstate->trash_delete_nesting < PyTrash_UNWIND_LEVEL); PyDict_Type.tp_dealloc((PyObject *)self); + ++tstate->trash_delete_nesting; + + Py_TRASHCAN_SAFE_END(self) }; /* tp_repr */ |