Search code examples
c++memory-leakssegmentation-faultvalgrind

Can a memory leak be a reason of a segmentation fault?


I have a complicated application with lots of third-party libraries, dynamically loaded plugins. And something causes the app to crash (SIGSEGV) after main exits. The call stack points to unknown addresses so not only I can't debug, I don't even have an idea where the crash happens.

I tried to run the app with Valgrind - it shows leaks (some kilobytes) but I believe that they are false positives and/or I can't do anything about them because they are coming from the third-party.

My question: I believe that memory leaks can't cause a segmentation fault, at least I can't find out the possible scenario. But since I'm not sure I'd like to hear cases when a leak can break the program (assuming it's not a crazy leak when I'm simply out of memory).


Solution

  • No, memory leaks by themselves would not cause a segmentation fault. However, memory leaks usually indicate sloppy code, and in sloppy code other issues, which would cause a segmentation fault, are likely to be present.