Detecting Memory Leaks with Valgrind

Detecting Memory Leaks with Valgrind

Valgrind is a memory checker, it is designed to be as non-intrusive as possible.
It works directly with existing executables. You don’t need to recompile, relink, or otherwise modify the program to be checked.

In this presentation we will explore how to use Valgrind to detect memory errors in a program written in C/C++
using MemCheck tool. What kind of problems can be detected with Valgrind 's memcheck:

1. Not releasing acquired memory using delete/free.(example code )
2. Writing into an array with an index that's out of bounds. (example code )
3. Trying to reference/dereference a pointer that is not yet initialized. (example code )
4. Trying to dereference a pointer that is already freed. (example code )
5. Passing system call parameters with inadequate buffers for read/write; i.e., if your program makes a system call passing an invalid buffer. (example code )
6. Uses of undefined variable values. (example code )

All the previous situations can give rise to memory errors, causing the program to terminate abruptly.
This is particularly dangerous in safety- and mission-critical systems, where such abrupt program termination can have catastrophic consequences.

Let's illustrate the usage of Valgrind through the
following scenarios:
1. Valgrind command line tool.(example)
2. QtCreator integration of Valgrind.
3. Eclipse integration of Valgrind using LinuxTools.

A final introduction to best practices when developing software:
1. C++11 unique_ptr<> illustrated with Valgrind.
2. Security hole discovered using Valgrind.

Edizione 2013 nella track Track1.