[Python-Dev] Debug entry points for PyMalloc
Skip Montanaro
skip@pobox.com
Sat, 23 Mar 2002 15:44:49 -0600
>> #define PYMALLOC_CLEANBYTE 0xCB /* uninitialized memory */
>> #define PYMALLOC_DEADBYTE 0xDB /* free()ed memory */
>> #define PYMALLOC_FORBIDDENBYTE 0xFB /* unusable memory */
>>
>> The debug malloc/free/realloc use these as follows. Note that this
>> stuff is done regardless of whether PyMalloc handles the request
>> directly or passes it on to the platform malloc (in fact, the debug
>> entry points won't know and won't care).
Any possibility that the __LINE__ or __FILE__:__LINE__ at which a chunk of
memory was freed could be imprinted as ASCII in freed memory without
changing the API? I'd find something like
<0340><0340><0340><0340><0340>
or
<object.c:0340><object.c:0340>
more useful than a string of
0xDB0xDB0xDB0xDB0xDB0xDB0xDB0xDB
bytes. I did something similar in a small single-file library I've been
working on, though I didn't pay much attention to preserving the malloc/free
API because, like I said, it was something small. I simply changed all
free() calls to something like
MARK_TERRITORY(s, strlen(s), __LINE__);
free(s);
(The second arg was appropriate to the size of the memory chunk being
freed.)
Skip