]> sourceware.org Git - glibc.git/blobdiff - malloc/mcheck.c
Update.
[glibc.git] / malloc / mcheck.c
index 0d32fc17f763836b9470e70a9824b10c3573f25c..971e2e52c6d737611f8ef0c8f8176f68c49660e7 100644 (file)
@@ -1,5 +1,5 @@
 /* Standard debugging hooks for `malloc'.
-   Copyright (C) 1990-1997, 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1990-1997, 1999, 2000, 2001 Free Software Foundation, Inc.
    Written May 1989 by Mike Haertel.
 
    This library is free software; you can redistribute it and/or
@@ -103,9 +103,8 @@ checkhdr (hdr)
   return status;
 }
 
-static void check_all __P ((void));
-static void
-check_all ()
+void
+mcheck_check_all ()
 {
   /* Walk through all the active blocks and test whether they were tempered
      with.  */
@@ -172,7 +171,7 @@ freehook (ptr, caller)
      const __ptr_t caller;
 {
   if (pedantic)
-    check_all ();
+    mcheck_check_all ();
   if (ptr)
     {
       struct hdr *hdr = ((struct hdr *) ptr) - 1;
@@ -200,7 +199,7 @@ mallochook (size, caller)
   struct hdr *hdr;
 
   if (pedantic)
-    check_all ();
+    mcheck_check_all ();
 
   __malloc_hook = old_malloc_hook;
   if (old_malloc_hook != NULL)
@@ -230,7 +229,7 @@ reallochook (ptr, size, caller)
   __malloc_size_t osize;
 
   if (pedantic)
-    check_all ();
+    mcheck_check_all ();
 
   if (ptr)
     {
@@ -271,7 +270,8 @@ reallochook (ptr, size, caller)
   return (__ptr_t) (hdr + 1);
 }
 
-static void mabort __P ((enum mcheck_status status));
+static void mabort __P ((enum mcheck_status status))
+     __attribute__ ((noreturn));
 static void
 mabort (status)
      enum mcheck_status status;
@@ -315,6 +315,10 @@ mcheck (func)
   /* These hooks may not be safely inserted if malloc is already in use.  */
   if (__malloc_initialized <= 0 && !mcheck_used)
     {
+      /* We call malloc() once here to ensure it is initialized.  */
+      void *p = malloc (0);
+      free (p);
+
       old_free_hook = __free_hook;
       __free_hook = freehook;
       old_malloc_hook = __malloc_hook;
@@ -331,8 +335,10 @@ int
 mcheck_pedantic (func)
       void (*func) __P ((enum mcheck_status));
 {
-  pedantic = 1;
-  return mcheck (func);
+  int res = mcheck (func);
+  if (res == 0)
+    pedantic = 1;
+  return res;
 }
 
 enum mcheck_status
This page took 0.029828 seconds and 5 git commands to generate.