about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--malloc/mtrace.c9
2 files changed, 10 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index fbac1c5d5d..1031d4d5c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2012-11-19  Pino Toscano  <toscano.pino@tiscali.it>
 
+	* malloc/mtrace.c (muntrace): Reset MALLSTREAM and the hooks before
+	finalizing MALLSTREAM.
+
 	* sysdeps/mach/hurd/syncfs.c: New file.
 
 2012-11-19  Siddhesh Poyarekar  <siddhesh@redhat.com>
diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index d7a032a86a..3f02c71822 100644
--- a/malloc/mtrace.c
+++ b/malloc/mtrace.c
@@ -364,11 +364,16 @@ muntrace ()
   if (mallstream == NULL)
     return;
 
-  fprintf (mallstream, "= End\n");
-  fclose (mallstream);
+  /* Do the reverse of what done in mtrace: first reset the hooks and
+     MALLSTREAM, and only after that write the trailer and close the
+     file.  */
+  FILE *f = mallstream;
   mallstream = NULL;
   __free_hook = tr_old_free_hook;
   __malloc_hook = tr_old_malloc_hook;
   __realloc_hook = tr_old_realloc_hook;
   __memalign_hook = tr_old_memalign_hook;
+
+  fprintf (f, "= End\n");
+  fclose (f);
 }