DDJ has a nice article, Illusions of Safety, about avoiding common causes of C program crash.

We've all done it. I remember an app that I wrote that crashed on one function, but only when running in debug mode. It turned out that the problem was actually where the program tried to print out a debug message to the log - I was using sprintf, and the text message had got bigger than the string I was trying to write to.

These things can be tough to find, in my case the sprintf trashed the stack, so the crash occurred not at the point where the error was, but when the function tried to exit.