0

The following program crashes at the null-pointer dereference:

#include <stdlib.h>

char *p;

int main(void) {
    p = malloc(42);
    p = NULL;
    *p = 0;
    return 0;
}

When executed with Valgrind, the memory leak is still reported (despite the crash). However, when using Leak Sanitizer by compiling the program with -fsanitize=leak, the program crashes and the leak gets unreported.

Is there a way to obtain a report from Leak Sanitizer when the program crashes?

Alex Zhi
  • 183
  • 5
  • Why would you *care*? If the program is terminated (whether by crashing or terminating gracefully), all (normal) memory is reclaimed by the OS *anyway*. – EOF Jan 27 '17 at 19:01
  • What's worst? The crash or the memory leak? Most people would say the crash, so that should be the first priority to fix. – Some programmer dude Jan 27 '17 at 19:04
  • Well, in this case Valgrind might help to detect the crash cause by reporting the leak. – Eugene Sh. Jan 27 '17 at 19:06

0 Answers0