Valgrind - Memcheck

Valgrind is a tool for checking memory leaks, corruption, uninitialized variables and profiling.
In this lab, we use a number of example programs. You will examine the example programs with valgrind and find out files that contain memeory problems.
Introductory youtube video is available here.

  1. Download exp0.cc.
  2. Frist, take a look at the code and examine the problem.
    cat exp0.cc
  3. Compile the program
    g++ exp0.cc
  4. Run it.
    ./a.out
  5. Run it again with valgrind.
    valgrind ./a.out
  6. You will see the distressing messages and instructions. Rerun with an option for searching memory leaks.
    valgrind --leak-check=full ./a.out
  7. If it is still noisy, add the -q (quiet) option.
    valgrind --leak-check=full -q ./a.out
  8. The message is still not informative enough. Recompile the code with -g (debug information) so that valgrind can pinpoint which line of the code has the memory-leak problem.
    g++ -g exp0.cc
    valgrind --leak-check=full -q ./a.out

  9. Now, download the following set of files: exp1.cc, exp2.cc, exp3.cc, exp4.cc, exp5.cc, and exp6.cc. You will need to pass arguments for exp6 (the number of strings and string values): ./a.out 3 aaa bbb ccc
  10. Repeating the above instructions on each file and submit the files that have memory problems along with valgrind output that specifies it. Please name the log file as "log".
    valgrind --leak-check=full -q ./a.out > tmp1.out
    ...

    ~cs253/bin/checkin L4R# exp9.cc exp10.cc exp11.cc log

    This is an example log file for exp0.cc.
    [exp0.cc]
    40 bytes in 1 blocks are definitely lost in loss record 1 of 1
    by 0x40073D: main (exp0.cc:7)

Grading:

10 points: All problematic files are submitted.
9 points: More than half of problems are found.
8 points: Less than half of problems are found.

Note: Please use the exact name given.
         Do not share what you have found with others. If you have a question, ask TA for help.