Is it possible to make valgrind ignore certain libraries?

Assuming you are running the memcheck tool and you want to ignore Leak errors in libcrypto only, you could put a suppression like:

{
   ignore_libcrypto_conditional_jump_errors
   Memcheck:Leak
   ...
   obj:*/libcrypto.so.*
}

… into a file and pass it to valgrind with --suppressions=*FILENAME*.

To ignore Leak errors in all shared libraries under any lib directory (/lib, /lib64, /usr/lib, /usr/lib64, …):

{
   ignore_unversioned_libs
   Memcheck:Leak
   ...
   obj:*/lib*/lib*.so
}
{
   ignore_versioned_libs
   Memcheck:Leak
   ...
   obj:*/lib*/lib*.so.*
}

It is unlikely, but you may need to add additional variations of the directory pattern to account for the locations of the X11 and GTK libraries.

Beware that this will ignore errors caused by any callbacks you wrote that were invoked by the libraries. Catching errors in those callbacks could almost be done with:

{
   ignore_unversioned_libs
   Memcheck:Leak
   obj:*/lib*/lib*.so
   ...
   obj:*/lib*/lib*.so
}
{
   ignore_versioned_libs
   Memcheck:Leak
   obj:*/lib*/lib*.so.*
   ...
   obj:*/lib*/lib*.so.*
}

… but this reveals errors in calls by a library that use the Valgrind malloc. Since valgrind malloc is injected directly into the program text — not loaded as a dynamic library — it appears in the stack the same way as your own code does. This allows Valgrind to track the allocations, but also makes it harder to do exactly what you have asked.

FYI: I am using valgrind 3.5.

Leave a Comment