valgrind

Valgrind is an add-on UNIX utility to help detect memory leaks. It is a development tool, and makes a program run about twice as slowly.

  1. Bring up a previously installed command line environment. This could be the command line within Replit, or you could use ssh to connect to bertvm, using: ssh reed@bertvm.cs.uic.edu
    (where you will put your own netid instead of "reed")

  2. Use the editor of your choice (nano, vi, or the Replit editor) to create a program such as test.c shown below. For these ongoing instructions we will assume the program you have created is named test.c

  3. From the command line compile your program with debugging on:
    gcc -g test.c
    By default this will create an executable file named a.out in the same directory.

  4. Run valgrind on the executable version of your program
    valgrind ./a.out
    The dot '.' at the front of ./a.out means "current directory".

  5. To find out which malloc caused the memory leak, run valgrind as:
    valgrind --leak-check=full ./a.out


Sample starting point program for valgrind exercize: