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.
Tags: C++ code debugging libraries open-source validating-malloc
Posted on: November 17th, 2003 under code.
Posted on: November 17th, 2003 under code.