Go to the previous, next section.
You can ask malloc to check the consistency of dynamic storage by
using the mcheck function. This function is a GNU extension,
declared in `malloc.h'.
Function: int mcheck (void (*abortfn) (void))
Calling mcheck tells malloc to perform occasional
consistency checks. These will catch things such as writing
past the end of a block that was allocated with malloc.
The abortfn argument is the function to call when an inconsistency
is found. If you supply a null pointer, the abort function is
used.
It is too late to begin allocation checking once you have allocated
anything with malloc. So mcheck does nothing in that
case. The function returns -1 if you call it too late, and
0 otherwise (when it is successful).
The easiest way to arrange to call mcheck early enough is to use
the option `-lmcheck' when you link your program; then you don't
need to modify your program source at all.
Go to the previous, next section.