Using Valgrind

The valgrind utility can be used to detect dynamic memory problems and to detect invalid memory accesses. To use valgrind make sure you compile your code with the -g option.

To generate full information when looking for uninitialized values you should use the --track-origins=yes option. For details associated with leaked memory use the --leak-check=full. You should always use --track-origins=yes. To run valgrind:

valgrind --track-origins=yes a.out

If you are using input redirection:

valgrind --track-origins=yes a.out < public01.in

The following is an example of using valgrind. If your program is reading uninitialized values you will see the message "uninitialised value of" next to additional information (usually line numbers).

Use of uninitialised value of size 8
==43225== at 0x4E90122: _IO_vfscanf (in /usr/lib64/libc-2.17.so)
==43225== by 0x4E9DE8A: scanf (in /usr/lib64/libc-2.17.so)
==43225== by 0x400710: process (gp2.c:24)
==43225== by 0x40079B: main (gp2.c:36)

In this example you should look at lines 24 and 36.
           

Run valgrind as you are developing your code.

Additional valgrind information at http://www.cprogramming.com/debugging/valgrind.html

Web Accessibility