Saturday, August 30, 2014

Memory Testing Issues

The next step is to start using C++ smart pointers (described in the next post).  One use for smart pointers will be to replace the complicated code used to track the handling of tokens and the reporting of various errors (for example, memory leaks for tokens not freed).  Smart pointers will make this code unnecessary.  Before starting I thought it was a good idea to make sure the memory test scripts still worked.

There were no memory errors reported when using Qt 4.8.1 (installed with Mint13 or Ubuntu 12.04) or Qt 4.8.2 (installed with the kubuntu backports to get the latest KDE).  However, when building the application with Qt 4.8.6 (the latest Qt 4.8 that was installed from source), memory errors were reported.  The CMake build file was set up to generate the error suppression file from a template using the detected version and directory of Qt.  This file was not tested with newer versions of Qt.

It appeared that with Qt 4.8.6, memory errors were reported differently (which was also the case with Qt 4.8.4, also built from source).  After examining the output for each version of Qt, a common error suppressions file template was created that works with each of these four versions of Qt (other versions were not tested).

As with GDB, valgrind (the memory testing utility) only supports the new debug symbols output from GCC 4.8.1 starting with version 3.8.0 (3.7.0 is installed in Mint13).  Version 3.9.0 is the latest available from source code.  However, version 3.7.0 appears to work fine, including within Qt Creator.  The new errors suppressions file also works with valgrind 3.9.0.  Click Continue... for details on installing 3.9.0 from source, but this shouldn't be necessary on Mint 13 (Unbuntu 12.04).  The valgrind 3.10.0.SVN installed on Mint 17 (Ubuntu 14.04) reports errors differently and does not work with this error suppression file (for now 3.9.0 would have to be installed from source).

[branch cpp11 commit a2069aae24]

The source code for the latest Valgrind utility source can be found on Valgrind's Current Releases page.  The latest version available for download at this time is 3.9.0.  (Getting the latest version 3.10.0 from the SVN repository is beyond the scope of this post.)  Once downloaded, change to the directory with the downloaded file and execute the following commands (adjust according for the version downloaded):

tar xvaf ../Downloads/valgrind-3.9.0.tar.bz2
cd valgrind-3.9.0
./configure
make -j4           
(adjust 4 for the number cores present for a faster build)
sudo make install
This will install valgrind into /usr/local/bin by default.  The system valgrind is also at /usr/bin.  To install these utilities to a different path (for example off your home directory like in ~/bin), use the --prefix=<PATH> option on the configure command line for a desired.  This path has to be before the /usr/bin path in the PATH environment variable so that the new versions will be found before the system versions.  Alternatively, the prefix could be set to /usr/bin to overwrite the system versions, but this is something that I don't recommend.

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)