mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-07 06:43:00 +03:00
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.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,5 +1,17 @@
|
|||||||
2004-08-21 Ulrich Drepper <drepper@redhat.com>
|
2004-08-21 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
* dlfcn/Makefile: Don't build eval.c anymore.
|
* dlfcn/Makefile: Don't build eval.c anymore.
|
||||||
|
|
||||||
2004-08-20 Roland McGrath <roland@frob.com>
|
2004-08-20 Roland McGrath <roland@frob.com>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* Malloc implementation for multiple threads without lock contention.
|
/* Malloc implementation for multiple threads without lock contention.
|
||||||
Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Wolfram Gloger <wg@malloc.de>, 2001.
|
Contributed by Wolfram Gloger <wg@malloc.de>, 2001.
|
||||||
|
|
||||||
@@ -20,10 +20,6 @@
|
|||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
#ifndef DEFAULT_CHECK_ACTION
|
|
||||||
#define DEFAULT_CHECK_ACTION 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* What to do if the standard debugging hooks are in place and a
|
/* What to do if the standard debugging hooks are in place and a
|
||||||
corrupt pointer is detected: do nothing (0), print an error message
|
corrupt pointer is detected: do nothing (0), print an error message
|
||||||
(1), or call abort() (2). */
|
(1), or call abort() (2). */
|
||||||
@@ -71,9 +67,6 @@ memalign_hook_ini(alignment, sz, caller)
|
|||||||
return public_mEMALIGn(alignment, sz);
|
return public_mEMALIGn(alignment, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int check_action = DEFAULT_CHECK_ACTION;
|
|
||||||
|
|
||||||
/* Whether we are using malloc checking. */
|
/* Whether we are using malloc checking. */
|
||||||
static int using_malloc_checking;
|
static int using_malloc_checking;
|
||||||
|
|
||||||
@@ -106,18 +99,7 @@ __malloc_check_init()
|
|||||||
__realloc_hook = realloc_check;
|
__realloc_hook = realloc_check;
|
||||||
__memalign_hook = memalign_check;
|
__memalign_hook = memalign_check;
|
||||||
if(check_action & 1)
|
if(check_action & 1)
|
||||||
{
|
malloc_printf_nc (1, "malloc: using debugging hooks\n");
|
||||||
#ifdef _LIBC
|
|
||||||
_IO_flockfile (stderr);
|
|
||||||
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
|
|
||||||
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "malloc: using debugging hooks\n");
|
|
||||||
#ifdef _LIBC
|
|
||||||
((_IO_FILE *) stderr)->_flags2 |= old_flags2;
|
|
||||||
_IO_funlockfile (stderr);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A simple, standard set of debugging hooks. Overhead is `only' one
|
/* A simple, standard set of debugging hooks. Overhead is `only' one
|
||||||
@@ -234,21 +216,7 @@ top_check()
|
|||||||
if((char*)t + chunksize(t) == mp_.sbrk_base + main_arena.system_mem ||
|
if((char*)t + chunksize(t) == mp_.sbrk_base + main_arena.system_mem ||
|
||||||
t == initial_top(&main_arena)) return 0;
|
t == initial_top(&main_arena)) return 0;
|
||||||
|
|
||||||
if(check_action & 1)
|
malloc_printf_nc (check_action, "malloc: top chunk is corrupt\n");
|
||||||
{
|
|
||||||
#ifdef _LIBC
|
|
||||||
_IO_flockfile (stderr);
|
|
||||||
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
|
|
||||||
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "malloc: top chunk is corrupt\n");
|
|
||||||
#ifdef _LIBC
|
|
||||||
((_IO_FILE *) stderr)->_flags2 |= old_flags2;
|
|
||||||
_IO_funlockfile (stderr);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if(check_action & 2)
|
|
||||||
abort();
|
|
||||||
|
|
||||||
/* Try to set up a new top chunk. */
|
/* Try to set up a new top chunk. */
|
||||||
brk = MORECORE(0);
|
brk = MORECORE(0);
|
||||||
@@ -299,21 +267,8 @@ free_check(mem, caller) Void_t* mem; const Void_t *caller;
|
|||||||
p = mem2chunk_check(mem);
|
p = mem2chunk_check(mem);
|
||||||
if(!p) {
|
if(!p) {
|
||||||
(void)mutex_unlock(&main_arena.mutex);
|
(void)mutex_unlock(&main_arena.mutex);
|
||||||
if(check_action & 1)
|
|
||||||
{
|
malloc_printf_nc(check_action, "free(): invalid pointer %p!\n", mem);
|
||||||
#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();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if HAVE_MMAP
|
#if HAVE_MMAP
|
||||||
@@ -347,21 +302,7 @@ realloc_check(oldmem, bytes, caller)
|
|||||||
oldp = mem2chunk_check(oldmem);
|
oldp = mem2chunk_check(oldmem);
|
||||||
(void)mutex_unlock(&main_arena.mutex);
|
(void)mutex_unlock(&main_arena.mutex);
|
||||||
if(!oldp) {
|
if(!oldp) {
|
||||||
if(check_action & 1)
|
malloc_printf_nc(check_action, "realloc(): invalid pointer %p!\n", oldmem);
|
||||||
{
|
|
||||||
#ifdef _LIBC
|
|
||||||
_IO_flockfile (stderr);
|
|
||||||
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
|
|
||||||
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "realloc(): invalid pointer %p!\n", oldmem);
|
|
||||||
#ifdef _LIBC
|
|
||||||
((_IO_FILE *) stderr)->_flags2 |= old_flags2;
|
|
||||||
_IO_funlockfile (stderr);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if(check_action & 2)
|
|
||||||
abort();
|
|
||||||
return malloc_check(bytes, NULL);
|
return malloc_check(bytes, NULL);
|
||||||
}
|
}
|
||||||
oldsize = chunksize(oldp);
|
oldsize = chunksize(oldp);
|
||||||
|
@@ -280,6 +280,9 @@ extern "C" {
|
|||||||
/* For uintptr_t. */
|
/* For uintptr_t. */
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* For va_arg, va_start, va_end. */
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Debugging:
|
Debugging:
|
||||||
|
|
||||||
@@ -1498,6 +1501,7 @@ static size_t mUSABLe(Void_t*);
|
|||||||
static void mSTATs(void);
|
static void mSTATs(void);
|
||||||
static int mALLOPt(int, int);
|
static int mALLOPt(int, int);
|
||||||
static struct mallinfo mALLINFo(mstate);
|
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 Void_t* internal_function mem2mem_check(Void_t *p, size_t sz);
|
||||||
static int internal_function top_check(void);
|
static int internal_function top_check(void);
|
||||||
@@ -1966,6 +1970,9 @@ typedef struct malloc_chunk* mbinptr;
|
|||||||
#define unlink(P, BK, FD) { \
|
#define unlink(P, BK, FD) { \
|
||||||
FD = P->fd; \
|
FD = P->fd; \
|
||||||
BK = P->bk; \
|
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; \
|
FD->bk = BK; \
|
||||||
BK->fd = FD; \
|
BK->fd = FD; \
|
||||||
}
|
}
|
||||||
@@ -2327,6 +2334,15 @@ __malloc_ptr_t weak_variable (*__memalign_hook)
|
|||||||
void weak_variable (*__after_morecore_hook) __MALLOC_P ((void)) = NULL;
|
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 -------------------- */
|
/* ------------------- Support for multiple arenas -------------------- */
|
||||||
#include "arena.c"
|
#include "arena.c"
|
||||||
|
|
||||||
@@ -4164,21 +4180,7 @@ _int_free(mstate av, Void_t* mem)
|
|||||||
here by accident or by "design" from some intruder. */
|
here by accident or by "design" from some intruder. */
|
||||||
if (__builtin_expect ((uintptr_t) p > (uintptr_t) -size, 0))
|
if (__builtin_expect ((uintptr_t) p > (uintptr_t) -size, 0))
|
||||||
{
|
{
|
||||||
if (check_action & 1)
|
malloc_printf_nc (check_action, "free(): invalid pointer %p!\n", mem);
|
||||||
{
|
|
||||||
#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 ();
|
|
||||||
return;
|
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
|
#ifdef _LIBC
|
||||||
# include <sys/param.h>
|
# include <sys/param.h>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user