[egenix-users] mx base 2.1.0b5 ref count bug?

David Rushby davidrushby at yahoo.com
Tue Apr 26 15:39:32 CEST 2005


I'm using a heavy-debug build of Python 2.4.1 on i386 Linux.  The
Python interpreter was configured with a command similar to:
  OPT="-DPy_DEBUG -DCOUNT_ALLOCS" ./configure --prefix=...
--without-pymalloc

mx base 2.0.6, built with this Python interpreter, segfaulted when I
tried to use it; I didn't try to pursue that issue.

mx base 2.1.0b5 works fairly well, but causes the Python interpreter to
fail a reference counting integrity check and abort when bogus
arguments are passed to mx.DateTime.DateTime.  Example:
------------------------------------------------------------
py24d -c "import mx.DateTime as dt; dt.DateTime(-1, 13, 32)"
Fatal Python error: UNREF invalid object
Aborted
------------------------------------------------------------

I have no familiarity with the mx code base, but from looking at
mx/DateTime/mxDateTime/mxDateTime.c, the problem appears to be that
function 'mxDateTime_Free' is registered as the destructor for type
'mxDateTime_Type', but 'mxDateTime_Free' is called explicitly by
'mxDateTime_Deallocate', which is called by
'mxDateTime_FromDateAndTime' in case of error, and 'mxDateTime_Free' is
then called again by the Python garbage collector (even though the
object in question has already been subjected to 'PyObject_Del()' by
the previous execution of 'mxDateTime_Free').

In other words:
------------------------------------------------------------
mxDateTime_FromDateAndTime(erroneous args)
  -> mxDateTime_Deallocate(datetime)
    -> mxDateTime_Free(datetime)
      -> PyObject_Del(datetime)
...
[Python garbage collector]
  -> mxDateTime_Free(datetime)
    -> PyObject_Del(datetime)   /* aborts */
------------------------------------------------------------

Perhaps 'mxDateTime_FromDateAndTime' should call 'Py_DECREF(datetime)'
instead of 'mxDateTime_Deallocate' in the 'onError' handler, or
'mxDateTime_Deallocate' should call 'Py_DECREF(datetime)' instead of 'mxDateTime_Free(datetime)'?

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the egenix-users mailing list