In addition to the above, if you find yourself getting frustrated hunting for a bug using valgrind or a similar execution profiler, you should perhaps consider using a static analysis tool, such as lint. Personally, I use PC-LINT, which catches all sorts of these types of bugs.