]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
SF bug 840829: weakref callbacks and gc corrupt memory.
authorTim Peters <tim.peters@gmail.com>
Wed, 12 Nov 2003 20:43:28 +0000 (20:43 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 12 Nov 2003 20:43:28 +0000 (20:43 +0000)
commitadd09b4149b17afa30aa042dbb718b9d9ec741c3
treee3d9f2501d6143ff2d27a50a7d93674c99dde7cd
parent045f1de57ed524d5dbaab92fea8eabc59b33d6f2
SF bug 840829:  weakref callbacks and gc corrupt memory.

subtype_dealloc():  This left the dying object exposed to gc, so that
if cyclic gc triggered during the weakref callback, gc tried to delete
the dying object a second time.  That's a disaster.  subtype_dealloc()
had a (I hope!) unique problem here, as every normal dealloc routine
untracks the object (from gc) before fiddling with weakrefs etc.  But
subtype_dealloc has obscure technical reasons for re-registering the
dying object with gc (already explained in a large comment block at
the bottom of the function).

The fix amounts to simply refraining from reregistering the dying object
with gc until after the weakref callback (if any) has been called.

This is a critical bug (hard to predict, and causes seemingly random
memory corruption when it occurs).  I'll backport it to 2.3 later.
Lib/test/test_weakref.py
Misc/NEWS
Objects/typeobject.c