Silence Known Issues With Valgrind Suppression Files
Write and maintain a Valgrind suppression file with --gen-suppressions, wildcards and match-leak-kinds so known library noise stops hiding real bugs.

A Valgrind run on a real program usually ends with errors that are not yours: a graphics driver that reads uninitialised memory, a library that keeps a block reachable until exit, a runtime that does something odd on purpose. If you leave them in, every report has the same thirty lines of noise, and a new bug hides among them. If you ignore the whole report, you stop reading it. A suppression file is the answer: it tells Valgrind to skip errors that match a pattern, so what remains is yours to fix. This post builds one with Valgrind 3.24 on Linux 6.12, explains the format, shows how to generate entries, keep them narrow, and check that they still match. The first post in the series covers how to run Memcheck, and the later one on CI covers using a suppression file in an automatic gate.
What a suppression is
A suppression is a description of an error, in terms of its kind and the call stack where it happened. When Memcheck is about to print an error, it compares it with every suppression loaded. If the kind matches and the stack matches, the error is counted as suppressed and not printed. The file format is described in the Valgrind manual on suppressions. A stack match is made frame by frame, from the innermost frame outward, using function names (fun:) or object file names (obj:).
Valgrind already ships a default set for the C library and the dynamic linker, in files under its installation directory, so the first things you see in a run are your own. You add yours with --suppressions=FILE, and you can give the option more than once.
Generate entries instead of writing them
Writing the stack by hand is error-prone. Let Valgrind do it. Run with --gen-suppressions=all, and after each error it prints a block you can paste into a file:
valgrind --leak-check=full --gen-suppressions=all ./app 2> vg.logFor a leak in a library the log contains, after the normal report:
==7210== 24 bytes in 1 blocks are still reachable in loss record 3 of 18
==7210== at 0x4846828: malloc (vg_replace_malloc.c:381)
==7210== by 0x4B8E7A2: ??? (in /usr/lib/x86_64-linux-gnu/libfoo.so.1.4)
==7210== by 0x4B8F001: foo_init (in /usr/lib/x86_64-linux-gnu/libfoo.so.1.4)
==7210== by 0x109289: main (app.c:14)
==7210==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/usr/lib/x86_64-linux-gnu/libfoo.so.1.4
fun:foo_init
fun:main
}Copy the block into a file such as app.supp, and give it a real name in place of <insert_a_suppression_name_here>. The name shows up in the summary of used suppressions, so make it describe the cause: libfoo-init-reachable-24b. The block has four parts:
The name on the first line.
The tool and error kind,
Memcheck:Leak. Other kinds includeMemcheck:Cond(a conditional jump on an undefined value),Memcheck:Addr4(invalid read or write of 4 bytes),Memcheck:Value8andMemcheck:Paramfor system call arguments.For leaks, a
match-leak-kinds:line listing which categories to match:definite,indirect,possible,reachable, orall.The stack, innermost first, written as
fun:NAMEfor a function,obj:PATHfor an object file, and...as a wildcard for any number of frames.
Run again with the file:
valgrind --leak-check=full --suppressions=app.supp ./app==7280== LEAK SUMMARY:
==7280== definitely lost: 0 bytes in 0 blocks
==7280== indirectly lost: 0 bytes in 0 blocks
==7280== possibly lost: 0 bytes in 0 blocks
==7280== still reachable: 0 bytes in 0 blocks
==7280== suppressed: 24 bytes in 1 blocksThe line suppressed: 24 bytes in 1 blocks tells you that the file matched.
Keep entries narrow
A suppression that is too broad is worse than none. If you write fun:malloc and ... as a stack, you silence every leak in the program, including the one you will introduce next month. The rules to follow:
Name the library. Use
obj:for the library that is at fault, so only blocks allocated through it match. A frame in your own code (fun:mainor a function you own) should stay in the stack, so a leak from the same library through a different caller of yours is still reported.Limit the kind.
match-leak-kinds: reachablehides only blocks that were still reachable. It does not hide a definite loss from the same stack, which is a real bug in how you use the library.Do not suppress your own code. If the error stack's first frame is in a file you own, fix it. A suppression there is a deferred bug.
**Use
...only in the middle, where frames differ legitimately.** For instance, a library may reach the allocation through different internal call chains depending on options:
{
libfoo-internal-cache-reachable
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
...
fun:foo_init
...
}The ... after malloc lets any number of internal frames sit between the allocator and foo_init. The trailing one means the caller chain beyond foo_init does not matter. Compare that with the previous entry, which names main and so would not match if foo_init were called from another function.
Be careful with stripped libraries. When a library has no symbols, Valgrind prints ??? for its functions and the generated suppression holds only obj:. That is still correct, but it matches every function in the object, so check that it is narrow enough or install the library's debug symbols and regenerate.
Suppress an uninitialised-value error
For a Conditional jump or move depends on uninitialised value(s) error inside a third-party library, the entry looks like this:
{
libdrv-cond-render
Memcheck:Cond
obj:/usr/lib/x86_64-linux-gnu/libdrv.so.3
obj:/usr/lib/x86_64-linux-gnu/libdrv.so.3
fun:app_render
}Note that --track-origins=yes does not affect matching; origins are not part of the stack Valgrind matches against. You generate and test the file with or without the flag.
Check that the file still works
Suppression files rot. A library upgrade changes function names, and the entry stops matching while the file stays, so the noise returns, or worse, an entry that matched too widely keeps hiding a real bug. Two habits keep the file honest.
First, run with -v once in a while. At the end of the run it prints a used_suppression line for each entry that matched, with its count. It shows which entries are actually in use:
--7301-- used_suppression: 1 libfoo-init-reachable-24b app.supp:3An entry that never shows up in this list for a full test run can be deleted. Second, keep a comment next to each entry. Valgrind suppression files accept lines starting with # as comments, so record the library version and the reason:
## libfoo 1.4.2 keeps its option table reachable until exit by design
{
libfoo-init-reachable-24b
Memcheck:Leak
...
}When the library version changes, review its entries. Record the version in the comment rather than a date, since the version is what decides whether the entry is still needed.
Where suppressions should not be used
Suppression is for issues you cannot or will not fix, in code you do not control. It is the wrong tool for memory errors in your own code, which you should fix, and for noise caused by running an optimized build whose inlining confuses the stack, where the fix is to rebuild with -O0. And treat a growing file as a warning sign: if every release adds a dozen entries, a dependency is in poor shape, and you should consider replacing it.


