diff options
Diffstat (limited to 'malloc')
-rw-r--r-- | malloc/malloc.c | 7 | ||||
-rw-r--r-- | malloc/mcheck.c | 28 |
2 files changed, 18 insertions, 17 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c index 058c156be4..3d4933cd7c 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1522,7 +1522,7 @@ static unsigned long max_mmapped_mem = 0; #endif /* Already initialized? */ -int __malloc_initialized = 0; +int __malloc_initialized = -1; /* The following two functions are registered via thread_atfork() to @@ -1596,8 +1596,8 @@ ptmalloc_init __MALLOC_P((void)) const char* s; #endif - if(__malloc_initialized) return; - __malloc_initialized = 1; + if(__malloc_initialized >= 0) return; + __malloc_initialized = 0; #if defined _LIBC || defined MALLOC_HOOKS /* With some threads implementations, creating thread-specific data or initializing a mutex may call malloc() itself. Provide a @@ -1638,6 +1638,7 @@ ptmalloc_init __MALLOC_P((void)) if(__malloc_initialize_hook != NULL) (*__malloc_initialize_hook)(); #endif + __malloc_initialized = 1; } /* There are platforms (e.g. Hurd) with a link-time hook mechanism. */ diff --git a/malloc/mcheck.c b/malloc/mcheck.c index 47d35f1f1f..4547a31299 100644 --- a/malloc/mcheck.c +++ b/malloc/mcheck.c @@ -21,10 +21,10 @@ or (US mail) as Mike Haertel c/o Free Software Foundation. */ #ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include <malloc.h> -#include <mcheck.h> -#include <stdio.h> +# define _MALLOC_INTERNAL +# include <malloc.h> +# include <mcheck.h> +# include <stdio.h> #endif /* Old hook values. */ @@ -49,9 +49,9 @@ struct hdr unsigned long int magic; /* Magic number to check header integrity. */ }; -#if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) -#include <string.h> -#define flood memset +#if defined _LIBC || defined STDC_HEADERS || defined USG +# include <string.h> +# define flood memset #else static void flood __P ((__ptr_t, int, __malloc_size_t)); static void @@ -196,25 +196,25 @@ mabort (status) switch (status) { case MCHECK_OK: - msg = _("memory is consistent, library is buggy"); + msg = _("memory is consistent, library is buggy\n"); break; case MCHECK_HEAD: - msg = _("memory clobbered before allocated block"); + msg = _("memory clobbered before allocated block\n"); break; case MCHECK_TAIL: - msg = _("memory clobbered past end of allocated block"); + msg = _("memory clobbered past end of allocated block\n"); break; case MCHECK_FREE: - msg = _("block freed twice"); + msg = _("block freed twice\n"); break; default: - msg = _("bogus mcheck_status, library is buggy"); + msg = _("bogus mcheck_status, library is buggy\n"); break; } #ifdef _LIBC __libc_fatal (msg); #else - fprintf (stderr, "mcheck: %s\n", msg); + fprintf (stderr, "mcheck: %s", msg); fflush (stderr); abort (); #endif @@ -229,7 +229,7 @@ mcheck (func) abortfunc = (func != NULL) ? func : &mabort; /* These hooks may not be safely inserted if malloc is already in use. */ - if (!__malloc_initialized && !mcheck_used) + if (__malloc_initialized <= 0 && !mcheck_used) { old_free_hook = __free_hook; __free_hook = freehook; |