1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

malloc: Change top_check return type to void

After commit ec2c1fcefb,
(malloc: Abort on heap corruption, without a backtrace), the function
always returns 0.
This commit is contained in:
Florian Weimer
2017-08-31 12:02:59 +02:00
parent 8715f25630
commit 5129873a8e
3 changed files with 20 additions and 15 deletions

View File

@ -1,3 +1,10 @@
2017-08-31 Florian Weimer <fweimer@redhat.com>
* malloc/malloc.c (top_check): Change return type to void. Remove
internal_function.
* malloc/hooks.c (top_check): Likewise.
(malloc_check, realloc_check, memalign_check): Adjust.
2017-08-30 Joseph Myers <joseph@codesourcery.com> 2017-08-30 Joseph Myers <joseph@codesourcery.com>
[BZ #21457] [BZ #21457]

View File

@ -228,8 +228,7 @@ mem2chunk_check (void *mem, unsigned char **magic_p)
} }
/* Check for corruption of the top chunk. */ /* Check for corruption of the top chunk. */
static int static void
internal_function
top_check (void) top_check (void)
{ {
mchunkptr t = top (&main_arena); mchunkptr t = top (&main_arena);
@ -240,7 +239,7 @@ top_check (void)
prev_inuse (t) && prev_inuse (t) &&
(!contiguous (&main_arena) || (!contiguous (&main_arena) ||
(char *) t + chunksize (t) == mp_.sbrk_base + main_arena.system_mem))) (char *) t + chunksize (t) == mp_.sbrk_base + main_arena.system_mem)))
return 0; return;
malloc_printerr ("malloc: top chunk is corrupt"); malloc_printerr ("malloc: top chunk is corrupt");
} }
@ -257,7 +256,8 @@ malloc_check (size_t sz, const void *caller)
} }
__libc_lock_lock (main_arena.mutex); __libc_lock_lock (main_arena.mutex);
victim = (top_check () >= 0) ? _int_malloc (&main_arena, sz + 1) : NULL; top_check ();
victim = _int_malloc (&main_arena, sz + 1);
__libc_lock_unlock (main_arena.mutex); __libc_lock_unlock (main_arena.mutex);
return mem2mem_check (victim, sz); return mem2mem_check (victim, sz);
} }
@ -329,7 +329,7 @@ realloc_check (void *oldmem, size_t bytes, const void *caller)
else else
{ {
/* Must alloc, copy, free. */ /* Must alloc, copy, free. */
if (top_check () >= 0) top_check ();
newmem = _int_malloc (&main_arena, bytes + 1); newmem = _int_malloc (&main_arena, bytes + 1);
if (newmem) if (newmem)
{ {
@ -341,13 +341,11 @@ realloc_check (void *oldmem, size_t bytes, const void *caller)
} }
else else
{ {
if (top_check () >= 0) top_check ();
{
INTERNAL_SIZE_T nb; INTERNAL_SIZE_T nb;
checked_request2size (bytes + 1, nb); checked_request2size (bytes + 1, nb);
newmem = _int_realloc (&main_arena, oldp, oldsize, nb); newmem = _int_realloc (&main_arena, oldp, oldsize, nb);
} }
}
/* mem2chunk_check changed the magic byte in the old chunk. /* mem2chunk_check changed the magic byte in the old chunk.
If newmem is NULL, then the old chunk will still be used though, If newmem is NULL, then the old chunk will still be used though,
@ -396,8 +394,8 @@ memalign_check (size_t alignment, size_t bytes, const void *caller)
} }
__libc_lock_lock (main_arena.mutex); __libc_lock_lock (main_arena.mutex);
mem = (top_check () >= 0) ? _int_memalign (&main_arena, alignment, bytes + 1) : top_check ();
NULL; mem = _int_memalign (&main_arena, alignment, bytes + 1);
__libc_lock_unlock (main_arena.mutex); __libc_lock_unlock (main_arena.mutex);
return mem2mem_check (mem, bytes); return mem2mem_check (mem, bytes);
} }

View File

@ -1022,7 +1022,7 @@ static void* _mid_memalign(size_t, size_t, void *);
static void malloc_printerr(const char *str) __attribute__ ((noreturn)); static void malloc_printerr(const char *str) __attribute__ ((noreturn));
static void* internal_function mem2mem_check(void *p, size_t sz); static void* internal_function mem2mem_check(void *p, size_t sz);
static int internal_function top_check(void); static void top_check (void);
static void internal_function munmap_chunk(mchunkptr p); static void internal_function munmap_chunk(mchunkptr p);
#if HAVE_MREMAP #if HAVE_MREMAP
static mchunkptr internal_function mremap_chunk(mchunkptr p, size_t new_size); static mchunkptr internal_function mremap_chunk(mchunkptr p, size_t new_size);