[Python-Dev] Py_CLEAR to avoid crashes

"Martin v. Löwis" martin at v.loewis.de
Tue Feb 19 00:56:43 CET 2008


> That sucks.  Most Py_DECREF calls are probably okay but it's going
> to be hard to find the ones that are not.

Methinks that

egrep 'DECREF\([a-zA-Z0-9_]->[a-zA-Z0-9_]+\)' */*.c

gives a good overview - you should never DECREF a variable on heap.
In the trunk, this command finds 36 candidates. Now, some of them
are in tp_dealloc methods, so they shouldn't cause problems - but
it can't hurt to replace them with Py_CLEAR, either.

Regards,
Martin


More information about the Python-Dev mailing list