Reputation: 15
I'm running valgrind in a script to find memory issues only by the return value of valgrind (I don't want to print anything to the screen).
Using this line:
valgrind --tool=memcheck --leak-check=full --error-exitcode=3 {c program} < {input file} > /dev/null 2> {errors redirection file}
The return value ($?) that I get is the return value of the c-program and not the one of valgrind.
How can I do it right?
Thanks :)
Upvotes: 0
Views: 1158
Reputation: 2711
Documentation on the valgrind site says:
"--error-exitcode= [default: 0]
Specifies an alternative exit code to return if Valgrind reported any errors in the run. When set to the default value (zero), the return value from Valgrind will always be the return value of the process being simulated. When set to a nonzero value, that value is returned instead, if Valgrind detects any errors. This is useful for using Valgrind as part of an automated test suite, since it makes it easy to detect test cases for which Valgrind has reported errors, just by inspecting return codes."
The implication is that if valgrind doesn't detect errors, it will still return the value of the process being simulated. Therefore, you should pick some value to use that the C program doesn't ever return when using this option.
Upvotes: 1