mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
malloc: preserve errno on mcheck hooks [BZ #17924]
Similar to the fix 69fda43b8d
, save and restore errno for the hook
functions used for MALLOC_CHECK_=3.
It fixes the malloc/tst-free-errno-mcheck regression.
Checked on x86_64-linux-gnu.
This commit is contained in:
@ -260,6 +260,8 @@ free_check (void *mem, const void *caller)
|
|||||||
if (!mem)
|
if (!mem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
int err = errno;
|
||||||
|
|
||||||
#ifdef USE_MTAG
|
#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. */
|
||||||
@ -274,13 +276,17 @@ free_check (void *mem, const void *caller)
|
|||||||
{
|
{
|
||||||
__libc_lock_unlock (main_arena.mutex);
|
__libc_lock_unlock (main_arena.mutex);
|
||||||
munmap_chunk (p);
|
munmap_chunk (p);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Mark the chunk as belonging to the library again. */
|
/* Mark the chunk as belonging to the library again. */
|
||||||
(void)TAG_REGION (chunk2rawmem (p), CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
|
(void)TAG_REGION (chunk2rawmem (p), CHUNK_AVAILABLE_SIZE (p)
|
||||||
|
- CHUNK_HDR_SZ);
|
||||||
_int_free (&main_arena, p, 1);
|
_int_free (&main_arena, p, 1);
|
||||||
__libc_lock_unlock (main_arena.mutex);
|
__libc_lock_unlock (main_arena.mutex);
|
||||||
}
|
}
|
||||||
|
__set_errno (err);
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
realloc_check (void *oldmem, size_t bytes, const void *caller)
|
realloc_check (void *oldmem, size_t bytes, const void *caller)
|
||||||
|
Reference in New Issue
Block a user