If you have used pointers, you might be aware of its associated strength and risk. A bad pointer can result in crash due to various reasons. It can be accessing invalid memory or corrupting stack. These issues are generally hard to reproduce/debug making life more difficult. How to detect such issue at earliest and so, prevent it? Code review is the best. However, using automated tool to review code at runtime will be feasible for fairly big chunk of code.
There are various tools available for handling memory. Moreover, GCC compiler also provides option for enabling such checks. GCC option will normally provide easier way to produce binary which enables memory check at runtime.
AddressSanitizer (or ASan) is a programming tool that detects memory corruption bugs such as buffer overflows or accesses to a dangling pointer (use-after-free). AddressSanitizer is based on compiler instrumentation and directly-mapped shadow memory. AddressSanitizer can be currently enabled in GCC (starting from version 4.8[2]) using -fsanitize=address flag. On average, the instrumentation increases processing time by about 73% and memory usage by 340%.[3]
https://en.wikipedia.org/wiki/AddressSanitizer
https://gcc.gnu.org/gcc-4.8/changes.html
LeakSanitizer is a run-time memory leak detector. It can be combined with AddressSanitizer to get both memory error and leak detection, or used in a stand-alone mode. LSan adds almost no performance overhead until the very end of the process, at which point there is an extra leak detection phase.
http://clang.llvm.org/docs/LeakSanitizer.html
http://stackoverflow.com/questions/31177633/how-to-find-memory-leaks-with-clang
GCC has included -fsanitize=leak option for enabling memory leak detection.
https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
http://stackoverflow.com/questions/31210053/gcc-and-fsanitize-leak
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.
http://valgrind.org/
mtrace is the memory debugger included in the GNU C Library.
https://en.wikipedia.org/wiki/Mtrace
https://en.wikipedia.org/wiki/AddressSanitizer
https://gcc.gnu.org/gcc-4.8/changes.html
http://stackoverflow.com/questions/31210053/gcc-and-fsanitize-leak