Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 gcl (2.6.10-6) unstable; urgency=high
 .
   * 2.6.11pre test 5
Author: Camm Maguire <camm@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- gcl-2.6.10.orig/o/alloc.c
+++ gcl-2.6.10/o/alloc.c
@@ -1371,8 +1371,6 @@ DEFUN_NEW("GET-HOLE-SIZE",object,fSget_h
 
 static unsigned long start,end,gprof_on;
 static void *initial_monstartup_pointer;
-bool capture_gprof_array=1;
-object gprof_array=Cnil;
 
 void
 gprof_cleanup(void) {
@@ -1381,7 +1379,6 @@ gprof_cleanup(void) {
 
   if (initial_monstartup_pointer) {
     _mcleanup();
-    gprof_array=Cnil;
     gprof_on=0;
   }
 
@@ -1406,19 +1403,26 @@ gprof_cleanup(void) {
 
 }
     
- 
+static inline int
+my_monstartup(unsigned long start,unsigned long end) {
+
+  extern void monstartup(unsigned long,unsigned long);
+
+  monstartup(start,end);
+
+  return 0;
+
+}
 
 DEFUN_NEW("GPROF-START",object,fSgprof_start,SI,0,0,NONE,OO,OO,OO,OO,(void),"") {
 
-  extern void monstartup(unsigned long,unsigned long);
   extern void *GCL_GPROF_START;
   static int n;
 
   if (!gprof_on) {
     start=start ? start : textstart;
     end=end ? end : textend;
-    capture_gprof_array=1;
-    monstartup(start,end);
+    writable_malloc_wrap(my_monstartup,int,start,end);
     gprof_on=1;
     if (!n && atexit(gprof_cleanup)) {
       FEerror("Cannot setup gprof_cleanup on exit", 0);
@@ -1457,7 +1461,6 @@ DEFUN_NEW("GPROF-QUIT",object,fSgprof_qu
   if (chdir(P_tmpdir))
     FEerror("Cannot change directory to tmpdir", 0);
   _mcleanup();
-  gprof_array=Cnil;
   if (snprintf(b1,sizeof(b1),"gprof %s",kcl_self)<=0)
     FEerror("Cannot write gprof command line", 0);
   if (!(pp=popen(b1,"r")))
@@ -1616,10 +1619,6 @@ malloc(size_t size) {
     massert(!atexit(gprof_cleanup));
     initial_monstartup_pointer=malloc_list->c.c_car->st.st_self;
   }
-  if (gprof_array==Cnil && capture_gprof_array && size>(textend-textstart)) {
-    gprof_array=malloc_list->c.c_car;
-    capture_gprof_array=0;
-  }
 #endif
   
   in_malloc=0;
