Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Treat (some) valgrind warnings as errors?

Tags:

c++

valgrind

Is it possible to change some valgrind warnings into errors?

In particular, I want to turn the probably lost warning into an error.

In the valgrind manual I found only information about how to suppress warnings.

Is there a way to do what I want?

like image 889
Why666 Avatar asked Feb 16 '15 15:02

Why666


People also ask

How can I see Valgrind errors?

Look for function names and line numbers If you compile your program with the -g flag, Valgrind will show you the function names and line numbers where errors occur.

Can Valgrind be wrong?

Yes, there are false positives with Valgrind, that's why it has suppression files for particular glibc and gcc versions, for example. The false positives may arise if you are using older valgrind with newer gcc and glibc, i.e., valgrind 3.3 with glibc 2.9.

Can Valgrind detect stack corruption?

In general, Valgrind detection of overflows in stack and global variables is weak to non-existant. Arguably, Valgrind is the wrong tool for that job. If you are on one of supported platforms, building with -fmudflap and linking with -lmudflap will give you much better results for these kinds of errors.

Can Valgrind detect double free?

Sometimes, running a program (including with valgrind) can show a double-free error while in reality, it's a memory corruption problem (for example a memory overflow). The best way to check is to apply the advice detailed in the answers : How to track down a double free or corruption error in C++ with gdb.


1 Answers

Since valgrind release 3.9, you can use the below command line options to better control what leak to reports, and what leaks to consider as errors.

   --show-leak-kinds=kind1,kind2,.. which leak kinds to show?
                                            [definite,possible]
   --errors-for-leak-kinds=kind1,kind2,..  which leak kinds are errors?
                                            [definite,possible]
like image 156
phd Avatar answered Nov 15 '22 07:11

phd