Debugging heap corruption

Regan Heath regan at netmail.co.nz
Mon Jul 30 03:16:32 PDT 2007


Vladimir Panteleev wrote:
> On Mon, 30 Jul 2007 12:03:15 +0300, Regan Heath <regan at netmail.co.nz>
> wrote:
> 
>> Vladimir Panteleev wrote: One method for finding heap corruption is
>> to write custom memory allocation, reallocation and free routines.
>> 
>> In the allocator you allocate extra memory before and after the
>> block you actually return, you initialise these padding blocks to
>> some known pattern and when it comes time to reallocate or free the
>> memory you verify the padding is intact and has not been modified.
>> 
>> This allows you to figure out which piece of memory has been
>> corrupted and how (overrun etc).
>> 
>> I used to use this to check I wasn't leaking any memory also but
>> with a GC that's no longer important.
>> 
>> I'm not sure whether D allows you to define global custom
>> allocators, anyone?  Or perhaps Tango has that capability?
> 
> That's exactly what Phobos's GC SENTINEL option is supposed to do
> (and is what I'll be looking at next). 

I haven't heard of "Phobos's GC SENTINEL option" what is it?  Where can
I read about it in the D docs?

 > I assume that what you said
> doesn't apply to D?

I'm not sure what you mean?  Which part of what I said are you assuming 
doesn't apply to D?

Regan



More information about the Digitalmars-d mailing list