summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2008-01-18 20:56:30 (GMT)
committerGuido van Rossum <guido@python.org>2008-01-18 20:56:30 (GMT)
commit9ff1a449732277c340fdf426e89d8460d2d8dd87 (patch)
tree6f1c91052a481c8f8c1463678472a6d56a631acb /Objects
parent4956d2b88981fd5a6481cd048d7efd514594b6e9 (diff)
downloadcpython-9ff1a449732277c340fdf426e89d8460d2d8dd87.zip
cpython-9ff1a449732277c340fdf426e89d8460d2d8dd87.tar.gz
cpython-9ff1a449732277c340fdf426e89d8460d2d8dd87.tar.bz2
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/classobject.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 89cca59..b4b17f9 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);