diff --git a/src/pike_memory.c b/src/pike_memory.c
index fdf241f5b4d0caf778c45095d3c4a320ae4611e9..9ba7dc79b7fea61ee5c6fc2fde4aa0048a63c225 100644
--- a/src/pike_memory.c
+++ b/src/pike_memory.c
@@ -10,7 +10,7 @@
 #include "pike_macros.h"
 #include "gc.h"
 
-RCSID("$Id: pike_memory.c,v 1.60 2000/03/24 16:25:46 grubba Exp $");
+RCSID("$Id: pike_memory.c,v 1.61 2000/04/04 20:35:57 hubbe Exp $");
 
 /* strdup() is used by several modules, so let's provide it */
 #ifndef HAVE_STRDUP
@@ -682,6 +682,15 @@ static MUTEX_T debug_malloc_mutex;
 #undef strdup
 #undef main
 
+
+#ifdef WRAP
+#define malloc __real_malloc
+#define free __real_free
+#define realloc __real_realloc
+#define calloc __real_calloc
+#define strdup __real_strdup
+#endif
+
 #define LOCATION char *
 #define LOCATION_NAME(X) ((X)+1)
 #define LOCATION_IS_DYNAMIC(X) ((X)[0]=='D')
@@ -1251,7 +1260,6 @@ void *debug_malloc(size_t s, LOCATION location)
   return m;
 }
 
-
 void *debug_calloc(size_t a, size_t b, LOCATION location)
 {
   void *m=debug_malloc(a*b,location);
@@ -1289,6 +1297,10 @@ void debug_free(void *p, LOCATION location, int mustfind)
   if(!p) return;
   mt_lock(&debug_malloc_mutex);
 
+#ifdef WRAP
+  mustfind=1;
+#endif
+
   mh=my_find_memhdr(p,0);
 
   if(verbose_debug_malloc || (mh && (mh->flags & MEM_WARN_ON_FREE)))
@@ -1376,6 +1388,33 @@ char *debug_strdup(const char *s, LOCATION location)
   return m;
 }
 
+#ifdef WRAP
+void *__wrap_malloc(size_t size)
+{
+  return debug_malloc(size, "Smalloc");
+}
+
+void *__wrap_realloc(void *m, size_t size)
+{
+  return debug_realloc(m, size, "Srealloc");
+}
+
+void *__wrap_calloc(size_t size,size_t num)
+{
+  return debug_calloc(size,num,"Scalloc");
+}
+
+void __wrap_free(void * size)
+{
+  return debug_free(size, "Sfree", 0);
+}
+
+void *__wrap_strdup(const char *s)
+{
+  return debug_strdup(s, "Sstrdup");
+}
+#endif
+
 
 void dump_memhdr_locations(struct memhdr *from,
 			   struct memhdr *notfrom)