]> granicus.if.org Git - python/commitdiff
Fix an edge case whereby the __del__() method of a classic class could
authorGuido van Rossum <guido@python.org>
Fri, 18 Jan 2008 20:53:37 +0000 (20:53 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 18 Jan 2008 20:53:37 +0000 (20:53 +0000)
create a new weakref to the object.

Objects/classobject.c

index 89cca5969df506d713f5b47d0e8496c76e535210..b4b17f90777a1d87b9a3893c3f6746749b333c88 100644 (file)
@@ -646,6 +646,16 @@ instance_dealloc(register PyInstanceObject *inst)
         */
        assert(inst->ob_refcnt > 0);
        if (--inst->ob_refcnt == 0) {
+
+               /* New weakrefs could be created during the finalizer call.
+                   If this occurs, clear them out without calling their
+                   finalizers since they might rely on part of the object
+                   being finalized that has already been destroyed. */
+               while (inst->in_weakreflist != NULL) {
+                       _PyWeakref_ClearRef((PyWeakReference *)
+                                            (inst->in_weakreflist));
+               }
+
                Py_DECREF(inst->in_class);
                Py_XDECREF(inst->in_dict);
                PyObject_GC_Del(inst);