This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brett.cannon
Recipients brett.cannon, dmalcolm, stutzbach
Date 2013-10-19.14:37:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
GCC defines an __attribute__ called 'cleanup' which attaches to a variable declaration and specifies a function to execute with an argument of a pointer to the variable when the block scope is left. Typically this is used to automate cleanup (much like smart pointers in C++), but we can't do that if we want to support compilers other than GCC (and Clang based on my testing). Cleanup's definition can be found at .

But what we can use it for is refcount verification. So if we defined a freed(PyObject **) cleanup function we could verify in a debug build that the memory in fact was erased with the memory pattern that a debug build overwrites memory with. If something is expected to have <= 1 refcount (i.e. the variable's value is to be returned assuming nothing went wrong) then we could check if it was freed or if it had exactly a refcount of 1. This obviously only works for local variables which are assigned fresh objects (since there is no way to measure the delta of a refcount from assignment to block exit), but it would still help detect some refleaks. It would also potentially help with Dave Malcolm's gcc refleak detector by providing hints as to what the expected outcome is.

Credit to David Stutzbach for suggesting this usage.
Date User Action Args
2013-10-19 14:37:31brett.cannonsetrecipients: + brett.cannon, stutzbach, dmalcolm
2013-10-19 14:37:31brett.cannonsetmessageid: <>
2013-10-19 14:37:31brett.cannonlinkissue19298 messages
2013-10-19 14:37:31brett.cannoncreate