I try to track down a memory leak in a c++ program using valgrind. The program is compiled with g++ and can be run without throwing any errors. Unfortunately valgrind alters the behaviour of my program in a way that it crashes after throwing a runtime-error. As this crash happens before reaching the relevant parts of the code, I have no chance to track down my memory leak.
The whole problem is illustrated by the attached console output.
myUser@computer:~$ ./myProgram input.xml
Processing...
Finished successfully...
----------------------
Hit Enter to continue...
myUser@computer:~$ valgrind --leak-check=yes --log-file=valgrindLog ./myProgram input.xml
Processing...
myProgram-error: Not working Polymorphism. Base class method called instead of derived class method. End-of-myProgram-error.
terminate called after throwing an instance of 'char const*'
Aborted
myUser@computer:~$ g++ -dumpversion
4.4.5
myUser@computer:~$ valgrind --version
valgrind-3.6.0.SVN-Debian
myUser@computer:~$ uname -r
2.6.35-30-generic
myUser@computer:~$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick
DISTRIB_DESCRIPTION="Ubuntu 10.10"
It is likely that valgrind is changing the behavior of your code because you have a bug more serious than a memory leak. Bug free, portable code probably won't throw exceptions just because you run it with valgrind.