? valgrind.diff
? build/win32/vs8/Makefile
? build/win32/vs8/Makefile.in
? glib/valgrind/Makefile
? glib/valgrind/Makefile.in
Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.501
diff -u -p -d -r1.501 configure.in
--- configure.in	13 Mar 2006 08:40:54 -0000	1.501
+++ configure.in	19 Mar 2006 15:42:35 -0000
@@ -2794,6 +2794,7 @@ build/win32/vs8/Makefile
 glib/Makefile
 glib/libcharset/Makefile
 glib/gnulib/Makefile
+glib/valgrind/Makefile
 gmodule/Makefile
 gmodule/gmoduleconf.h
 gobject/Makefile
Index: glib/Makefile.am
===================================================================
RCS file: /cvs/gnome/glib/glib/Makefile.am,v
retrieving revision 1.139
diff -u -p -d -r1.139 Makefile.am
--- glib/Makefile.am	1 Dec 2005 16:34:19 -0000	1.139
+++ glib/Makefile.am	19 Mar 2006 15:42:35 -0000
@@ -6,9 +6,9 @@ PRINTF_SUBDIR = gnulib
 printf_la = gnulib/libgnulib.la
 endif 
 
-SUBDIRS = libcharset $(PRINTF_SUBDIR)
+SUBDIRS = libcharset $(PRINTF_SUBDIR) valgrind
 
-DIST_SUBDIRS = libcharset gnulib
+DIST_SUBDIRS = libcharset gnulib valgrind
 
 INCLUDES = -I$(top_srcdir) -DG_LOG_DOMAIN=\"GLib\" \
 	$(GLIB_DEBUG_FLAGS) -DG_DISABLE_DEPRECATED -DGLIB_COMPILATION 
Index: glib/gslice.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gslice.c,v
retrieving revision 1.18
diff -u -p -d -r1.18 gslice.c
--- glib/gslice.c	14 Feb 2006 16:31:37 -0000	1.18
+++ glib/gslice.c	19 Mar 2006 15:42:35 -0000
@@ -41,6 +41,8 @@
 #include <windows.h>
 #include <process.h>
 #endif
+#include "valgrind/valgrind.h"
+#include "valgrind/memcheck.h"
 
 
 /* the GSlice allocator is split up into 4 layers, roughly modelled after the slab
@@ -747,8 +749,8 @@ thread_memory_magazine2_free (ThreadMemo
 }
 
 /* --- API functions --- */
-gpointer
-g_slice_alloc (gsize mem_size)
+static gpointer
+_g_slice_allocate (gsize mem_size, int zeroed)
 {
   gsize chunk_size;
   gpointer mem;
@@ -774,17 +776,29 @@ g_slice_alloc (gsize mem_size)
       g_mutex_unlock (allocator->slab_mutex);
     }
   else                          /* delegate to system malloc */
-    mem = g_malloc (mem_size);
+    mem = g_malloc (chunk_size);
+
+  if (G_LIKELY (mem)) {
+    if (zeroed)
+      memset (mem, 0, mem_size);
+
+    /* hint valgrind that this a newly allocated memory */
+    VALGRIND_MALLOCLIKE_BLOCK (mem, mem_size, chunk_size - mem_size, zeroed);
+  }
+
   return mem;
 }
 
 gpointer
+g_slice_alloc (gsize mem_size)
+{
+  return _g_slice_allocate (mem_size, 0);
+}
+
+gpointer
 g_slice_alloc0 (gsize mem_size)
 {
-  gpointer mem = g_slice_alloc (mem_size);
-  if (mem)
-    memset (mem, 0, mem_size);
-  return mem;
+  return _g_slice_allocate (mem_size, 1);
 }
 
 void
@@ -823,6 +837,8 @@ g_slice_free1 (gsize    mem_size,
         memset (mem_block, 0, mem_size);
       g_free (mem_block);
     }
+  /* valgrind hint that this is freeing memory */
+  VALGRIND_FREELIKE_BLOCK(mem_block, chunk_size - mem_size);
 }
 
 void
@@ -1092,8 +1108,13 @@ allocator_memalign (gsize alignment,
     }
   aligned_memory = g_trash_stack_pop (&compat_valloc_trash);
 #endif
-  if (!aligned_memory)
+  if (G_UNLIKELY (!aligned_memory))
     errno = err;
+  else
+    {
+      /* hint valgrind that this memory should not be accessed directly */
+      VALGRIND_MAKE_NOACCESS(aligned_memory, memsize);
+    }
   return aligned_memory;
 }
 
