Valgrind is a tool for detecting memory issues in programs. It simulates a host CPU and monitors all memory access operations. It does this by adding metadata on the status of all bytes of memory (alloced, initialized, etc.) and running the program as it updates this metadata. This can make the program run much slower, but it will detect many memory errors.
There is lots of info on Valgrind and similar tools. Here are a few:
Most Linux distros will have a package for Valgrind. For example, I installed it with:
sudo apt-get install valgrind
You run Valgrind by giving it the program you want to execute as an argument:
It will report any errors it finds and give suggestions about ways to resolve ambiguity in most cases.
Pull your repository and find the
simpletree project. We'll try using Valgrind on this project. Can you make Valgrind miss some memory errors? Try some of these things
- Remove initializations (child NULLs inits)
- Remove mallocs (right malloc)
- Add extra frees (free right child after subtree creation)
- Do not free (remove call to the empty function)