BUG: classobject.c

M.-A. Lemburg mal at lemburg.com
Mon Oct 11 08:24:48 EDT 1999


[CC to Guido because I think you have indeed found a bug here...]

Adrian Eyre wrote:
> 
> > The PyObject_* APIs return object references with incremented refcount.
> > You don't need the Py_INCREF here -- it would cause a memory leak.
> 
> Well. All I know is that the result of the PyObject_GetAttrString is
> returning an object with a refcount of 1. And since PyString_AS_STRING
> returns a pointer within the PyStringObject struct, then the
> Py_XDECREF causes this to become invalid. Perhaps the Py_XDECREF should
> be moved down to the line before the return.

Ah, now I get your point: you mean the fname pointer could possibly
point to the already free'ed string contents due to the DECREC being
done prior to formatting the representation.

That could be the case... guess you did find a bug ;-)
 
> Perhaps I've done something wrong. But I'm not sure how. If the
> refcount is one, it tends to suggest that this is a new reference.
> (i.e. the object didn't exist previously.) Do all PyMethodObjects
> have an attribute called '__name__'?

Yes. The additional code using PyObject_GetAttrString() was added
to allow arbitrary callable object to be used in place of the
method's function object. This was done to enable writing methods
in C rather than in Python for performance reasons.

Moving the Py_XDECREF in classobject.c:instancemethod_repr() just
in front of the return should fix the problem, just as you suggested.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    81 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list