Using Valgrind's Memcheck tool

Memcheck is Valgrind's default tool; you do not need to pass it explicitly, but can do so with the valgrind --tool=memcheck <program-to-execute with params> syntax.

As a trivial example, let's run Valgrind on the df(1) utility (on an Ubuntu box):

$ lsb_release -aNo LSB modules are available.Distributor ID:    UbuntuDescription:    Ubuntu 17.10Release:    17.10Codename:    artful$ df --version |head -n1df (GNU coreutils) 8.26$ valgrind df==1577== Memcheck, a memory error detector==1577== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.==1577== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info==1577== Command: df==1577== Filesystem     1K-blocks    Used Available Use% Mounted onudev 479724 0 479724 ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.