By default valgrind suppresses many leaks. I'm not even sure exactly
how it decides which ones to suppress, but certainly global variables
pointing to malloc’d data are suppressed, which is not useful
behaviour.
Tell valgrind to show all leaks. It won't give an error on them.
However to do this we also need a much more comprehensive list of
suppressions so that we don't constantly show unavoidable leaks in
(eg) dlopen. This adds separate files for each class of suppressions
in a new valgrind/ directory.
---
.gitignore | 1 +
Makefile.am | 2 +-
configure.ac | 3 +-
valgrind/Makefile.am | 47 ++++++++
valgrind/glibc.suppressions | 106 ++++++++++++++++++
.../nbdkit.suppressions | 21 +---
valgrind/perl.suppressions | 40 +++++++
wrapper.c | 3 +-
8 files changed, 205 insertions(+), 18 deletions(-)
diff --git a/.gitignore b/.gitignore
index 612c544..86ef6cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -97,3 +97,4 @@ Makefile.in
/tests/test-xz
/tests/test-xz-curl
/test-driver
+/valgrind/suppressions
diff --git a/Makefile.am b/Makefile.am
index 2b5d80d..a06e683 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,7 +40,6 @@ EXTRA_DIST = \
html/pod.css \
LICENSE \
OTHER_PLUGINS \
- valgrind-suppressions \
m4/.gitignore
CLEANFILES += html/*.html
@@ -60,6 +59,7 @@ nbdkit_DEPENDENCIES = config.status
SUBDIRS = \
bash \
docs \
+ valgrind \
include \
common/include \
src
diff --git a/configure.ac b/configure.ac
index a3e4457..cf931cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -834,6 +834,7 @@ AC_CONFIG_FILES([Makefile
src/Makefile
src/nbdkit.pc
tests/functions.sh
- tests/Makefile])
+ tests/Makefile
+ valgrind/Makefile])
AC_OUTPUT
diff --git a/valgrind/Makefile.am b/valgrind/Makefile.am
new file mode 100644
index 0000000..7312b79
--- /dev/null
+++ b/valgrind/Makefile.am
@@ -0,0 +1,47 @@
+# nbdkit
+# Copyright (C) 2018 Red Hat Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+include $(top_srcdir)/common-rules.mk
+
+suppressions_files = $(wildcard *.suppressions)
+
+EXTRA_DIST = $(suppressions_files)
+
+noinst_DATA = suppressions
+
+suppressions: $(suppressions_files)
+ rm -f $@ $@-t
+ cat $^ > $@-t
+ mv $@-t $@
+ chmod 0444 $@
+
+DISTCLEANFILES = suppressions
diff --git a/valgrind/glibc.suppressions b/valgrind/glibc.suppressions
new file mode 100644
index 0000000..6be59ac
--- /dev/null
+++ b/valgrind/glibc.suppressions
@@ -0,0 +1,106 @@
+# glibc valgrind suppressions
+# Copyright (C) 2016-2018 Red Hat Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+# Allow thread-local storage from pthread_create to leak.
+{
+ glibc_1
+ Memcheck:Leak
+ fun:calloc
+ ...
+ fun:_dl_allocate_tls
+}
+
+# Suppress leaks from dlopen. When running under valgrind we
+# deliberately don't run dlclose because otherwise valgrind cannot
+# print symbols. So it's expected that dlopen will leak.
+{
+ glibc_2
+ Memcheck:Leak
+ ...
+ obj:/usr/lib*/libdl-*
+}
+
+# bindtextdomain leaks.
+{
+ glibc_3
+ Memcheck:Leak
+ ...
+ fun:bindtextdomain
+}
+
+# Both gmtime_r and locatime_r leak some sort of timezone- related
+# struct inside glibc. These are used by the log filter and the
+# floppy plugin.
+{
+ glibc_4
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:tzset_internal
+}
+
+# __printf_chk leaks.
+{
+ glibc_5
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:__printf_chk
+}
+
+# iconv is very leaky, even if we close the handle.
+{
+ glibc_6
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:__gconv_open
+}
+
+{
+ glibc_7
+ Memcheck:Leak
+ fun:calloc
+ ...
+ fun:__gconv_open
+}
+
+# getaddrinfo leaks a memory allocation even though we
+# call freeaddrinfo.
+{
+ glibc_8
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:__check_pf
+ fun:getaddrinfo
+}
diff --git a/valgrind-suppressions b/valgrind/nbdkit.suppressions
similarity index 94%
rename from valgrind-suppressions
rename to valgrind/nbdkit.suppressions
index 671cd79..094d106 100644
--- a/valgrind-suppressions
+++ b/valgrind/nbdkit.suppressions
@@ -1,5 +1,5 @@
# nbdkit valgrind suppressions
-# Copyright (C) 2016 Red Hat Inc.
+# Copyright (C) 2016-2018 Red Hat Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -50,22 +50,13 @@
fun:allocate_stack
}
-# Allow thread-local storage from pthread_create to leak.
-{
- nbdkit_3
- Memcheck:Leak
- fun:calloc
- ...
- fun:_dl_allocate_tls
-}
-
# close methods are not guaranteed to be called if a connection is in
# progress when the server is being shut down, so leaks in various
# *_open functions are fairly inevitable. We simply have to check by
# hand that the following leaks are not possible under normal
# circumstances, and then add them to this list.
{
- nbdkit_4
+ nbdkit_3
Memcheck:Leak
fun:malloc
fun:error_open
@@ -73,7 +64,7 @@
}
{
- nbdkit_5
+ nbdkit_4
Memcheck:Leak
fun:malloc
fun:file_open
@@ -81,7 +72,7 @@
}
{
- nbdkit_6
+ nbdkit_5
Memcheck:Leak
fun:malloc
fun:memory_open
@@ -89,7 +80,7 @@
}
{
- nbdkit_7
+ nbdkit_6
Memcheck:Leak
fun:malloc
fun:null_open
@@ -97,7 +88,7 @@
}
{
- nbdkit_8
+ nbdkit_7
Memcheck:Leak
fun:malloc
fun:partition_open
diff --git a/valgrind/perl.suppressions b/valgrind/perl.suppressions
new file mode 100644
index 0000000..57d1fcc
--- /dev/null
+++ b/valgrind/perl.suppressions
@@ -0,0 +1,40 @@
+# Perl valgrind suppressions
+# Copyright (C) 2018 Red Hat Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+# Perl leaks lots of memory by design.
+{
+ perl_1
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:perl_construct
+}
diff --git a/wrapper.c b/wrapper.c
index eb50108..3fd499b 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -130,8 +130,9 @@ main (int argc, char *argv[])
passthru (VALGRIND);
passthru ("--vgdb=no");
passthru ("--leak-check=full");
+ passthru ("--show-leak-kinds=all");
passthru ("--error-exitcode=119");
- passthru_format ("--suppressions=%s/valgrind-suppressions", srcdir);
+ passthru_format ("--suppressions=%s/valgrind/suppressions", builddir);
passthru ("--trace-children=no");
passthru ("--run-libc-freeres=no");
passthru ("--num-callers=20");
--
2.19.0.rc0