I had to add several suppressions because Python leaks memory by
design, and also increase the max depth of valgrind stack traces
because Python stack traces are very deep.
Note that to do proper valgrinding of Python itself we would need to
specially recompile Python:
https://svn.python.org/projects/python/trunk/Misc/README.valgrind
---
tests/test-lang-plugins.c | 3 +-
valgrind/python.suppressions | 75 ++++++++++++++++++++++++++++++++++++
wrapper.c | 2 +-
3 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/tests/test-lang-plugins.c b/tests/test-lang-plugins.c
index af926f6..d0ebab3 100644
--- a/tests/test-lang-plugins.c
+++ b/tests/test-lang-plugins.c
@@ -57,8 +57,7 @@ main (int argc, char *argv[])
*/
s = getenv ("NBDKIT_VALGRIND");
if (s && strcmp (s, "1") == 0 &&
- (strcmp (LANG, "python") == 0 ||
- strcmp (LANG, "ruby") == 0 ||
+ (strcmp (LANG, "ruby") == 0 ||
strcmp (LANG, "tcl") == 0)) {
fprintf (stderr, "%s test skipped under valgrind.\n", LANG);
exit (77); /* Tells automake to skip the test. */
diff --git a/valgrind/python.suppressions b/valgrind/python.suppressions
new file mode 100644
index 0000000..bd20abe
--- /dev/null
+++ b/valgrind/python.suppressions
@@ -0,0 +1,75 @@
+# Python 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.
+
+# Python leaks lots of memory by design.
+{
+ python_1
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:Py_InitializeEx
+}
+
+{
+ python_2
+ Memcheck:Leak
+ fun:calloc
+ ...
+ fun:Py_InitializeEx
+}
+
+{
+ python_3
+ Memcheck:Leak
+ fun:realloc
+ ...
+ fun:Py_InitializeEx
+}
+
+# As far as I can tell there is no way to stop the Python object
+# (representing the compiled code?) from leaking from this API.
+{
+ python_4
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:PyRun_SimpleFileExFlags
+}
+
+# This seems like a bug in Python itself.
+{
+ python_5
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:Py_Finalize
+}
diff --git a/wrapper.c b/wrapper.c
index 3fd499b..f19c09a 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -135,7 +135,7 @@ main (int argc, char *argv[])
passthru_format ("--suppressions=%s/valgrind/suppressions", builddir);
passthru ("--trace-children=no");
passthru ("--run-libc-freeres=no");
- passthru ("--num-callers=20");
+ passthru ("--num-callers=100");
}
else {
s = getenv ("NBDKIT_GDB");
--
2.19.0.rc0