Can this be caused by errors in onward code, such as, memory leaks?
Memory leaks will cause your program to use up more and more memory, until it cannot get any more memory. And then it may crash with a segmentation fault because of this. http://en.wikipedia.org/wiki/Memory_leak
A stack overflow occurs when you use more stack memory than you have. You do this by calling a function recursively too many times, or by having local variables that are too big. http://en.wikipedia.org/wiki/Stack_overflow
Is there a reason why you can't show us the entire code?