Skip to content

Commit e509799

Browse files
author
guido.van.rossum
committed
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object. git-svn-id: http://svn.python.org/projects/python/trunk@60057 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 079d853 commit e509799

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Objects/classobject.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,16 @@ instance_dealloc(register PyInstanceObject *inst)
646646
*/
647647
assert(inst->ob_refcnt > 0);
648648
if (--inst->ob_refcnt == 0) {
649+
650+
/* New weakrefs could be created during the finalizer call.
651+
If this occurs, clear them out without calling their
652+
finalizers since they might rely on part of the object
653+
being finalized that has already been destroyed. */
654+
while (inst->in_weakreflist != NULL) {
655+
_PyWeakref_ClearRef((PyWeakReference *)
656+
(inst->in_weakreflist));
657+
}
658+
649659
Py_DECREF(inst->in_class);
650660
Py_XDECREF(inst->in_dict);
651661
PyObject_GC_Del(inst);

0 commit comments

Comments
 (0)