Catching memory errors

The goal of this exercise is to locate some common memory errors using Valgrind.

Steps

  1. Go to the exercise directory:

     cd esc15/hands-on/memory
    
  2. Examine the little test programs in this directory. You use them for dedicated little studies on container memory allocation behaviour:

  3. 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
    
  4. 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
    
  5. Find the problems, fix them, recompile and repeat until the issues are fixed.

References