From: Guido van Rossum Date: Fri, 18 Jan 2008 20:56:30 +0000 (+0000) Subject: Fix an edge case whereby the __del__() method of a classic class could X-Git-Tag: v2.6a1~554 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ff1a449732277c340fdf426e89d8460d2d8dd87;p=thirdparty%2FPython%2Fcpython.git Fix an edge case whereby the __del__() method of a classic class could create a new weakref to the object. --- diff --git a/Objects/classobject.c b/Objects/classobject.c index 89cca5969df5..b4b17f90777a 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -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);