Cmgui using valgrind
Brief Overview
Cmgui is tested with valgrind to check for memory leaks. This page is here to help anybody wanting to check their own work for memory leaks using valgrind on GNU/Linux.
Setup
Valgrind reports a lot of errors that won't directly relate to Cmgui. To help remove this chaf we ewill create a suppression file to help minimise the noise. To create our suppression list we will need.
- A build of Cmgui (preferably with debugging symbols)
- valgrind
- this extract suppressions bash script
Now we will run valgrind using our build of Cmgui using this command:
valgrind --leak-check=yes --gen-suppressions=all --track-origins=yes --quiet <cmgui-binary-name> 2> valgrind.output
where your <cmgui-binary-name> might be 'cmgui-wx'. When the Cmgui window appears quit the application.

Now extract the suppressions using the bash script (sorry to all those non-bash users).:
./extract_valgrind_suppressions.script -a valgrind.output
Notes:
- Some help and further options can be found with ./extract_valgrind_suppressions.script -h
- The '-a' option appends to our suppression list
For reasons unknown to me we need to iterate this process a couple of times. Valgrind it seems picks up some different leaks on different runs.
To repeat we use this command that uses the latest suppression file.:
valgrind --leak-check=yes --gen-suppressions=all --track-origins=yes --suppressions=cmgui.supp --quiet <cmgui-binary-name> 2> valgrind.output
then extract any new suppressions with:
./extract_valgrind_suppressions.script -a valgrind.output
We need to repeat this process until valgrind reports no more memory leaks.
Using Valgrind
Now we have created a suppression file that removes some of the noise from our system we can run Cmgui and test your own code for memory leaks using valgrind like so:
valgrind --leak-check=yes --track-origins=yes --suppressions=cmgui.supp --quiet <cmgui-binary-name> 2> valgrind.output
Seem familiar, well we have already been using valgrind but now you are on your own. Any new leaks detected could be memory leaks due to your changes and will need fixing if they are.