Debugging heap corruption

Vladimir Panteleev thecybershadow at gmail.com
Mon Jul 30 02:36:55 PDT 2007


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 assume that what you said doesn't apply to D?

-- 
Best regards,
  Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list