Patrick Audley // Validating Malloc

URI
Last Modifed (approximate)
Sun, 27 Nov 2011 20:00:00 -0800
Author
Publisher
Blackcat Systems
Language
en-GB

Validating Malloc: lightweight memory checking

A validating malloc in less than 200 lines of code (excluding comments). It’s written in C++ using the STL for efficiency but all function are declared using C linkage so you can use them from either C or C++ very easily.

There are lots of debugging malloc implementations, why another? Most of the implementations that I’ve found have been huge or not easy to understand and modify. This implementation is simple and well documented. It’s easy to understand how it works and modify it’s behaviour of you don’t like something.

Currently it understands and tries to catch:

  • Freeing already freed memory.
  • Reallocing pointers not previously malloced.
  • Over and under runs on malloced regions.
  • Failure to free memory before program exit.

It also contains utility routines that:

  • Hexdump regions on memory.
  • Allow annotation of memory regions.

which are useful on their own. Examples are provided of all the above in the “examples” directory of the distribution.