Electric Fence
Electric Fence helps you detect two common programming bugs:
software that overruns the boundaries of a malloc() memory allocation,
and software that touches a memory allocation that has been released
by free(). Unlike other malloc() debuggers, Electric Fence will detect
read accesses as well as writes, and it will pinpoint the exact
instruction that causes an error. It is commonly used with a debugger
(e.g., GDB) to detect where such memory
violations occur.
The Electric Fence manual page suggests the following strategy for
testing:
- Link with libefence.a as explained above.
- Run your program in a debugger and fix any overruns or accesses to free memory.
- Quit the debugger.
- Set EF_PROTECT_BELOW = 1 in the shell environment.
- Repeat step 2, this time repairing underruns if they occur.
- Quit the debugger.
- Read the restrictions in the section on WORD-ALIGNMENT AND
OVERRUN DETECTION. See if you can set EF_ALIGNMENT to 0 and repeat
step 2. Sometimes this will be too much work, or there will be
problems with library routines for which you don't have the source,
that will prevent you from doing this.