Mercurial > cpython-lru_cache-weakref
diff Objects/typeobject.c @ 30908:cd7624b025a0 2.3
Backport of fix for SF bug 840829, memory corruption in some cases of
weakref callbacks.
This is a critical bugfix. It's already been fixed on the trunk (2.4
development). I don't intend to backport it to the 22 line, but if a
2.2.4 ever gets released, this should be in it.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Thu, 13 Nov 2003 01:17:55 +0000 |
| parents | 6f15e73b59f2 |
| children | 81733c7a95c8 |
line wrap: on
line diff
--- a/Objects/typeobject.c Wed Nov 12 15:21:57 2003 +0000 +++ b/Objects/typeobject.c Thu Nov 13 01:17:55 2003 +0000 @@ -639,7 +639,11 @@ ++_PyTrash_delete_nesting; Py_TRASHCAN_SAFE_BEGIN(self); --_PyTrash_delete_nesting; - _PyObject_GC_TRACK(self); /* We'll untrack for real later */ + /* DO NOT restore GC tracking at this point. The weakref callback + * (if any) may trigger GC, and if self is tracked at that point, + * it will look like trash to GC and GC will try to delete it + * again. Double-deallocation is a subtle disaster. + */ /* Find the nearest base with a different tp_dealloc */ base = type; @@ -654,6 +658,7 @@ if (type->tp_weaklistoffset && !base->tp_weaklistoffset) PyObject_ClearWeakRefs(self); + _PyObject_GC_TRACK(self); /* We'll untrack for real later */ /* Maybe call finalizer; exit early if resurrected */ if (type->tp_del) {
