Is valgrind preventing a segfault I want to debug from occurring?

Does this mean that the bug is a heisenbug that won't occur when I use valgrind, and therefore valgrind isn't any use here?

No, you should still use Valgrind and fix all reported errors. The behavior you described is rather common and it is documented in Valgrind FAQ:

When a program runs under Valgrind, its environment is slightly different to when it runs natively. For example, the memory layout is different, and the way that threads are scheduled is different.

Most of the time this doesn't make any difference, but it can, particularly if your program is buggy. For example, if your program crashes because it erroneously accesses memory that is unaddressable, it's possible that this memory will not be unaddressable when run under Valgrind. Alternatively, if your program has data races, these may not manifest under Valgrind.


It is possible that the segmentation fault is hidden when compiled with debugging information or when memory placement is changed when running under valgrind. Of course this doesn't mean you cannot use valgrind to debug your application. You should fix all errors that valgrind reports such as invalid read/write errors. Fixing these errors should fix your segmentation fault problem.