Valgrind

Memory Leaks

Finding and fixing memory leaks in Ubuntu is a major step towards streamlining the platform for the widest range of devices, including the Nexus 7 and similar platforms.

Valgrind's memcheck tool is the traditional approach for this. It produces much better results though when debug symbols are present: the stack traces contain source code variable names instead of "???" and the implicated source code file names (and line numbers) are shown (instead of the lib file names).

A useful series of three of blog posts for understanding valgrind memcheck log files:

However, getting those debug symbols can be a chore: you have to figure out which packages own the linked objects, see whether there are debug packages for them, and install them (which permanently alters your system and uses up disk).

apport-valgrind

Starting in Ubuntu 13.04 Raring, the apport-valgrind binary package provides a wrapper to valgrind that does this mostly for you. On each execution (for example apport-valgrind notify-send), it:

  • Figures out the debug packages that should be used
  • Unpacks them into a sandbox directory in /tmp (which is automatically deleted after each execution: note that you can use the --sandbox-dir DIR argument to use a persistent sandbox). Note that the debug symbol packages are not installed, just unpacked into the sandbox, so the impact on the system is only the temporary disk space consumed.

  • Executes valgrind with the proper arguments to produce a thorough log file and that instructs valgrind to look in the sandbox DIR for debug symbols (in addition to the normal system directories)
  • Creates ./valgrind.log, which contains a report on memory leaks and, for each, a stack trace

Note: It is recommended to update your system before execution. This ensures your run time environment is consistent with the symbol packages unpacked into the sandbox DIR and therefore results in more complete stack traces from valgrind.

This blog post covers the rationale for apport-valgrind:

dbgysm and ddebs.ubuntu.com

apport-valgrind uses your current software sources (the debian archives) your system points to. That is, when looking for debug packages, apport-valgrind is limited to the archives your system already points to. Naturally, this includes the normal Ubuntu archives in which many 'dbg' packages exist, for example: libc6-dbg. Such dbg packages are created by the diverse world of package maintainers and may use different name patterns, which sometimes makes them hard or impossible to find mechanistically.

That's why ddebs.ubuntu.com exists: to automatically create a dbgsym package (for every binary package that should have one) at build time, and publish it on ddebs.ubuntu.com.

Therefore, you may want to add it to your system archives so that apport-valgrind can use dbgsym packages too. For example, you can add this to your /etc/apt/sources.list file for Raring main and universe:

deb http://ddebs.ubuntu.com raring main universe

This blog post provides some additional background on dbg and dbgsym packages and the ddebs archive:

Nexus7/Valgrind (last edited 2013-02-15 17:16:23 by knitzsche)