1

If a C++ program is called by a python script, how do you get Valgrind to check leaks in the C++ program and not just in the script? For example, if leak.cc contains the following code

int main() {
    int* p = new int;
}

and is compiled into a.out, and call_aout.py contains

#!/usr/bin/env python
import subprocess
subprocess.call(["./a.out"])

then running valgrind via

valgrind --track-origins=yes --leak-check=full -v ./call_aout.py

will not detect the memory leak in leak.cc, but calling it via

valgrind --track-origins=yes --leak-check=full -v ./a.out

will detect it.

2
  • Do you make valgrind track new, forked processes, too? Commented May 26, 2014 at 20:21
  • 1
    @KerrekSB: valgrind always follows forks, but he needs it to follow an exec Commented May 26, 2014 at 20:28

1 Answer 1

4

You want to use:

  --trace-children=yes

in your valgrind command line. Alternatively if you don't care about the python script all you can launch your subprocess with valgrind from within the script:

subprocess.call("valgrind --track-origins=yes --leak-check=full -v ./a.out")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.