diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-08-21 20:19:54 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-08-21 20:19:54 +0000 |
commit | 3e030bd5f9fa57f79a509565b5de6a1c0360d953 (patch) | |
tree | 69650e46945d47a7c32f6c1e0992e2251a81ba75 /malloc/malloc.c | |
parent | 51ea6fc094544328c08c367bc40a3b830b8fe7e8 (diff) | |
download | glibc-3e030bd5f9fa57f79a509565b5de6a1c0360d953.zip glibc-3e030bd5f9fa57f79a509565b5de6a1c0360d953.tar.gz glibc-3e030bd5f9fa57f79a509565b5de6a1c0360d953.tar.bz2 |
Update.
* malloc/hooks.c (DEFAULT_CHECK_ACTION): Moved to malloc.c.
(check_action): Likewise.
When printing error messages, use malloc_printf_nc now instead of
fiddling with the streams cancellation flag in every place.
* malloc/malloc.c (DEFAULT_CHECK_ACTION): New definition. Change
default to 3.
(check_action): New variable.
(unlink): Print error message and eventually terminate in case list
is corrupted.
(malloc_printf_nc): New function. Use it in _int_free.
Change proposed by Arjan van de Ven.
Diffstat (limited to 'malloc/malloc.c')
-rw-r--r-- | malloc/malloc.c | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c index 6e6c105..206be50 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -280,6 +280,9 @@ extern "C" { /* For uintptr_t. */ #include <stdint.h> +/* For va_arg, va_start, va_end. */ +#include <stdarg.h> + /* Debugging: @@ -1498,6 +1501,7 @@ static size_t mUSABLe(Void_t*); static void mSTATs(void); static int mALLOPt(int, int); static struct mallinfo mALLINFo(mstate); +static void malloc_printf_nc(int action, const char *template, ...); static Void_t* internal_function mem2mem_check(Void_t *p, size_t sz); static int internal_function top_check(void); @@ -1966,6 +1970,9 @@ typedef struct malloc_chunk* mbinptr; #define unlink(P, BK, FD) { \ FD = P->fd; \ BK = P->bk; \ + if (__builtin_expect (FD->bk != P || BK->fd != P, 0)) \ + malloc_printf_nc (check_action, \ + "corrupted double-linked list at %p!\n", P); \ FD->bk = BK; \ BK->fd = FD; \ } @@ -2327,6 +2334,15 @@ __malloc_ptr_t weak_variable (*__memalign_hook) void weak_variable (*__after_morecore_hook) __MALLOC_P ((void)) = NULL; +/* ---------------- Error behavior ------------------------------------ */ + +#ifndef DEFAULT_CHECK_ACTION +#define DEFAULT_CHECK_ACTION 3 +#endif + +static int check_action = DEFAULT_CHECK_ACTION; + + /* ------------------- Support for multiple arenas -------------------- */ #include "arena.c" @@ -4164,21 +4180,7 @@ _int_free(mstate av, Void_t* mem) here by accident or by "design" from some intruder. */ if (__builtin_expect ((uintptr_t) p > (uintptr_t) -size, 0)) { - if (check_action & 1) - { -#ifdef _LIBC - _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; -#endif - fprintf (stderr, "free(): invalid pointer %p!\n", mem); -#ifdef _LIBC - ((_IO_FILE *) stderr)->_flags2 |= old_flags2; - _IO_funlockfile (stderr); -#endif - } - if (check_action & 2) - abort (); + malloc_printf_nc (check_action, "free(): invalid pointer %p!\n", mem); return; } @@ -5404,6 +5406,35 @@ int mALLOPt(param_number, value) int param_number; int value; */ +/* Helper code. */ + +static void +malloc_printf_nc(int action, const char *template, ...) +{ + if (action & 1) + { +#ifdef _LIBC + _IO_flockfile (stderr); + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; +#endif + + va_list ap; + va_start (ap, template); + + vfprintf (stderr, template, ap); + + va_end (ap); + +#ifdef _LIBC + ((_IO_FILE *) stderr)->_flags2 |= old_flags2; + _IO_funlockfile (stderr); +#endif + } + if (action & 2) + abort (); +} + #ifdef _LIBC # include <sys/param.h> |