The goal of this exercise is to locate some common memory errors using Valgrind.
Steps
-
Go to the exercise directory:
cd esc15/hands-on/memory
-
Examine the little test programs in this directory. You use them for dedicated little studies on container memory allocation behaviour:
-
uninitialised.cc: Catch use of uninitialised memory.
-
array-smash.cc: Catch writing past the end of an object.
-
stack-smash.cc: Catch destruction of stack frame caused by overwriting outside bounds.
-
-
Build each program. The command is mentioned in each source file. To build all in one go:
grep -h Compile *.cc | sed 's|// Compile: ||' | sh -x
-
Run the programs under Valgrind:
valgrind --num-callers=50 --leak-check=full ./uninitialised valgrind --num-callers=50 --leak-check=full ./array-smash valgrind --num-callers=50 --leak-check=full ./stack-smash
-
Find the problems, fix them, recompile and repeat until the issues are fixed.