https://bugs.kde.org/show_bug.cgi?id=378732

--- Comment #11 from Mark Wielaard <m...@klomp.org> ---
(In reply to rrt from comment #10)
> What's the solution? A suppression? (It would seem to go against Valgrind's
> philosophy to say "build bash without the (debugging) wrappers"!) But as
> highlighted in the Debian thread, it would be good to fix this.
> 
> (The other obvious this would be simply to build --without-bash-malloc; the
> bash maintainers say this would have performance implications.)
> 
> Or can valgrind be taught about the wrappers?

Some distros (Fedora in particular) already build with --without-bash-malloc.
So it seems well tested. I would encourage the bash maintainer to contact the
glibc hackers and show them some benchmarks where the generic system malloc
performs worse than the bash one. They are really interested in making sure the
system malloc performs well for everybody.

If you want to keep the bash specific malloc implementation, but want to
restore the malloc interposition that breaks valgrind (and anything else that
depends on malloc interposition working correctly) then building with
-DDISABLE_MALLOC_WRAPPERS=1 seems like the easiest way forward. You might want
to ask the bash maintainers whether they feel that is a supported option. It
seems to only be used to some malloc debug/tracing messages.

There are ways to teach valgrind about allocators that don't obey malloc
interposition, but they are slightly involved. See
http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.clientreqs

If you do want to make the sh_xmalloc wrappers work for valgrind with normal
malloc interposition (like the normal xmalloc calls) then you could make them
just call malloc/free directly when running under valgrind (it would obviously
still be broken for other malloc interposers):

diff -ur bash-4.4/xmalloc.c bash-4.4.valgrind/xmalloc.c
--- bash-4.4/xmalloc.c  2016-08-26 15:08:14.000000000 +0200
+++ bash-4.4.valgrind/xmalloc.c 2017-04-14 15:49:26.832197332 +0200
@@ -35,6 +35,8 @@
 #  include "ansi_stdlib.h"
 #endif /* HAVE_STDLIB_H */

+#include <valgrind/valgrind.h>
+
 #include "error.h"

 #include "bashintl.h"
@@ -180,7 +182,10 @@
 #endif

   FINDBRK();
-  temp = sh_malloc (bytes, file, line);
+  if (RUNNING_ON_VALGRIND)
+    temp = malloc (bytes);
+  else
+    temp = sh_malloc (bytes, file, line);

   if (temp == 0)
     sh_allocerr ("xmalloc", bytes, file, line);
@@ -203,7 +208,10 @@
 #endif

   FINDBRK();
-  temp = pointer ? sh_realloc (pointer, bytes, file, line) : sh_malloc (bytes,
file, line);
+  if (RUNNING_ON_VALGRIND)
+    temp = pointer ? realloc (pointer, bytes) : malloc (bytes);
+  else
+    temp = pointer ? sh_realloc (pointer, bytes, file, line) : sh_malloc
(bytes, file, line);

   if (temp == 0)
     sh_allocerr ("xrealloc", bytes, file, line);
@@ -218,6 +226,11 @@
      int line;
 {
   if (string)
-    sh_free (string, file, line);
+    {
+      if (RUNNING_ON_VALGRIND)
+       free (string);
+      else
+       sh_free (string, file, line);
+    }
 }
 #endif

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to