--- glib/gslice.c	2007-03-08 20:01:39.000000000 -0800
+++ glib/gslice.c	2007-05-21 20:24:20.000000000 -0700
@@ -37,6 +37,12 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>             /* sysconf() */
 #endif
+#ifdef HAVE_VALGRIND_H          /* hypothetical (plausibly given in CFLAGS) */
+#include <valgrind.h>
+#endif
+#ifdef HAVE_VALGRIND_VALGRIND_H /* typical linux install location */
+#include <valgrind/valgrind.h>
+#endif
 #ifdef G_OS_WIN32
 #include <windows.h>
 #include <process.h>
@@ -275,6 +281,12 @@
     {
       config->always_malloc = TRUE;
     }
+#if defined(HAVE_VALGRIND_H) || defined(HAVE_VALGRIND_VALGRIND_H)
+  if (RUNNING_ON_VALGRIND)
+    {
+      config->always_malloc = TRUE;
+    }
+#endif
 }
 
 static void
--- configure.in	2007-03-08 20:01:50.000000000 -0800
+++ configure.in	2007-05-21 20:27:42.000000000 -0700
@@ -794,6 +794,13 @@
 AC_CHECK_HEADERS([sys/time.h sys/times.h sys/wait.h unistd.h values.h])
 AC_CHECK_HEADERS([sys/select.h sys/types.h stdint.h sched.h malloc.h])
 
+# check for valgrind headers (to disable gslice)
+# afaik, only valgrind/valgrind.h is used.
+# but valgrind.h seems like an idea for good measure.
+# (we could add a more sophisticated check to ensure RUNNING_ON_VALGRIND
+# is actually defined)
+AC_CHECK_HEADERS([valgrind.h valgrind/valgrind.h])
+
 # Checks for libcharset
 jm_LANGINFO_CODESET
 jm_GLIBC21
