[Python-bugs-list] [ python-Bugs-581210 ] __del__ reviving object causes Fatal Err

noreply@sourceforge.net noreply@sourceforge.net
Sat, 13 Jul 2002 21:47:22 -0700


Bugs item #581210, was opened at 2002-07-14 00:47
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=581210&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: joshua kobrin (jkobrin)
Assigned to: Nobody/Anonymous (nobody)
Summary: __del__ reviving object causes Fatal Err

Initial Comment:
In python 2.2.1:
If a class derived from object or having a metaclass creates a new reference to itself in __del__, you will get this:

Fatal Python error: GC object already in linked list

Here is a short sample program that will produce the error:

gRef = None

class Foo(object):
  def __del__(self):
    global gRef
    gRef = self
    
x = Foo()
del x


Based on a quick (sorry) look at the code, this seems to be a very simple error. 

On line 302 of Objects/typeobject.c, in the function call_finalizer, there is the following code:

if (--inst->ob_refcnt > 0) {
#ifdef COUNT_ALLOCS
  inst->ob_type->tp_frees--;
#endif
  _PyObject_GC_TRACK(inst);
  return; /* __del__ added a reference; don't delete now */
}

Now, I looked at this a couple weeks ago so I might be rembering wrong(sorry again), but I think this is what I figured:

The call to _PyObject_GC_TRACK is wrong here because the object has not yet been UTRACKED. On line 634 of Objects/classobject.c, there is identical code, but it is correct because UNTRACK  *has* already been called in this case. In other words, it looks like a cut and paste error.




----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=581210&group_id=5470