Valgrind: suppress memory memory leak reporting iff program crashed

309 Views Asked by At

Let's assume we have automated Valgrind testing setup with maximum diagnostics configured (--leak-check=yes --track-origins=yes etc.) However, on some tests the valgrinded process might crash with SIGSEGV due to some nondeterministic bug. In that case, the immediate diagnostics leading to SIGSEGV are useful, but Valgrind does not stop there and dumps every single live memory allocation as a leak, tens of thousands of them - which are useless in the case of random SIGSEGV.

Is there a way to configure Valgrind to

  • print any errors during the program execution and do not abort;
  • on regular exit, dump memory leaks;
  • on SIGSEGV/SIGABRT/SIGILL/SIG... exit, do not dump memory leaks?

EDIT: this has been logged at Valgrind bug tracker in 2011: https://bugs.kde.org/show_bug.cgi?id=265371

1

There are 1 best solutions below

0
On

valgrind leak search cannot be activated only for 'program normal exits' and de-activated for 'crash exits'.

You might maybe obtain this result by using --vgdb-error=0, then (using a script): use gdb+vgdb to connect to the valgrind gdbserver, catch the signals you want in gdb, and have gdb killing the process when the signal is received: the valgrind gdbserver has a command v.kill that will make valgrind exit without doing its usual 'end of life' leak search.