I've found valgrind a useful tool to check whether
memory is accessed properly. It keeps track where you have
allocated memory, where you have freed it, and where you
step out of line. It can produce reports of unreachable
memory, and unfreed memory when the program ends.