mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-28 00:21:52 +03:00
malloc: Use mtag_enabled instead of USE_MTAG
Use the runtime check where possible: it should not cause slow down in the !USE_MTAG case since then mtag_enabled is constant false, but it allows compiling the tagging logic so it's less likely to break or diverge when developers only test the !USE_MTAG case. Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
@ -262,11 +262,10 @@ free_check (void *mem, const void *caller)
|
|||||||
|
|
||||||
int err = errno;
|
int err = errno;
|
||||||
|
|
||||||
#ifdef USE_MTAG
|
|
||||||
/* Quickly check that the freed pointer matches the tag for the memory.
|
/* Quickly check that the freed pointer matches the tag for the memory.
|
||||||
This gives a useful double-free detection. */
|
This gives a useful double-free detection. */
|
||||||
*(volatile char *)mem;
|
if (__glibc_unlikely (mtag_enabled))
|
||||||
#endif
|
*(volatile char *)mem;
|
||||||
|
|
||||||
__libc_lock_lock (main_arena.mutex);
|
__libc_lock_lock (main_arena.mutex);
|
||||||
p = mem2chunk_check (mem, NULL);
|
p = mem2chunk_check (mem, NULL);
|
||||||
@ -310,11 +309,10 @@ realloc_check (void *oldmem, size_t bytes, const void *caller)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_MTAG
|
|
||||||
/* Quickly check that the freed pointer matches the tag for the memory.
|
/* Quickly check that the freed pointer matches the tag for the memory.
|
||||||
This gives a useful double-free detection. */
|
This gives a useful double-free detection. */
|
||||||
*(volatile char *)oldmem;
|
if (__glibc_unlikely (mtag_enabled))
|
||||||
#endif
|
*(volatile char *)oldmem;
|
||||||
|
|
||||||
__libc_lock_lock (main_arena.mutex);
|
__libc_lock_lock (main_arena.mutex);
|
||||||
const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
|
const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
|
||||||
|
@ -3286,11 +3286,10 @@ __libc_free (void *mem)
|
|||||||
if (mem == 0) /* free(0) has no effect */
|
if (mem == 0) /* free(0) has no effect */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef USE_MTAG
|
|
||||||
/* Quickly check that the freed pointer matches the tag for the memory.
|
/* Quickly check that the freed pointer matches the tag for the memory.
|
||||||
This gives a useful double-free detection. */
|
This gives a useful double-free detection. */
|
||||||
*(volatile char *)mem;
|
if (__glibc_unlikely (mtag_enabled))
|
||||||
#endif
|
*(volatile char *)mem;
|
||||||
|
|
||||||
int err = errno;
|
int err = errno;
|
||||||
|
|
||||||
@ -3352,11 +3351,10 @@ __libc_realloc (void *oldmem, size_t bytes)
|
|||||||
if (oldmem == 0)
|
if (oldmem == 0)
|
||||||
return __libc_malloc (bytes);
|
return __libc_malloc (bytes);
|
||||||
|
|
||||||
#ifdef USE_MTAG
|
|
||||||
/* Perform a quick check to ensure that the pointer's tag matches the
|
/* Perform a quick check to ensure that the pointer's tag matches the
|
||||||
memory's tag. */
|
memory's tag. */
|
||||||
*(volatile char*) oldmem;
|
if (__glibc_unlikely (mtag_enabled))
|
||||||
#endif
|
*(volatile char*) oldmem;
|
||||||
|
|
||||||
/* chunk corresponding to oldmem */
|
/* chunk corresponding to oldmem */
|
||||||
const mchunkptr oldp = mem2chunk (oldmem);
|
const mchunkptr oldp = mem2chunk (oldmem);
|
||||||
|
Reference in New Issue
Block a user