[Python-Dev] Py_CLEAR to avoid crashes
Nick Coghlan
ncoghlan at gmail.com
Mon Feb 18 13:36:53 CET 2008
Greg Ewing wrote:
> Martin v. Löwis wrote:
>> when some caller of PyEval_EvalFrameEx still carries
>> a pointer to some object that got deleted, and then still some code can
>> get hold of the then-deleted object.
>
> I seem to have missed the beginning of this discussion.
> I don't see what the problem is here. If a caller needs
> a pointer to an object, shouldn't it be holding a
> counted reference to it?
The problem is calls to Py_DECREF(self->attr) where some of the code
invoked by __del__ manages to find a way back around to reference
self->attr and gets access to a half-deleted object.
Amaury fixed a few of these recently by replacing the Py_DECREF calls
with Py_CLEAR calls (and added the relevant pathological destructors to
the test suite), but was wondering if there was a way to be more
systematic about fixing them. About the only idea I have is to grep the
source for all calls to Py_DECREF that contain a pointer deference and
manually check them to see if they should use Py_CLEAR instead.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list