I assume you're using valgrind's memcheck tool, which is what it is famous for. Since you are using valgrind already you might also try running your program through valgrind --tool=exp-ptrcheck
, which is an experimental tool that is designed to catch certain types of errors that memcheck will miss, including access checks for stack and global arrays, and use of pointers that happen to point to a valid object but not the object that was intended. It does this by using a completely different mechanism, essentially tracking each pointer into memory rather than tracking the memory itself, and through use of heuristics.
Be aware that the tool is definitely experimental, and I've found that it currently reports a number of false positives, but you may find that it catches something significant. Also only Linux is supported so far (no Mac OS X yet), and you should ensure that you are using the latest valgrind version (currently 3.5.0).