To help catch memory allocation errors in the system code,
the pvmd and libpvm use a
sanity-checking library called imalloc.
Imalloc functions are wrappers for the regular
libc functions
malloc(), realloc(), and free().
Upon detecting an error,
the imalloc functions abort the program
so the fault can be traced.

The following checks and functions are performed by imalloc:

The length argument to malloc is checked for insane values.
A length of zero is changed to one so it succeeds.

Each allocated block is tracked in a hash table to detect when
free() is called more than once on a block
or on something not from malloc().

i_malloc() and i_realloc()
write pads filled with a pseudo-random pattern
outside the bounds of each block,
which are checked by i_free()
to detect when something writes
past the end of a block.

i_free() zeros each block
before it frees it so further references may
fail and make themselves known.

Each block is tagged with a serial number and string to indicate its use.
The heap space can be dumped or sanity-checked at any time
by calling i_dump().
This helps find memory leaks.

Since the overhead of this checking is quite severe,
it is disabled at compile time by default.
Defining USE_PVM_ALLOC in the source makefile(s) switches it on.