aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-12-29 17:12:21 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-12-30 10:37:58 -0300
commit9835632cf43fd6d1f8b8f40a88892a45b6bfad6e (patch)
treee405c3d62988b2a6ccd63db757d890cf5c80a901
parent38a033ac85d62c64a2fc81b06c0acffcd4a113f5 (diff)
downloadglibc-9835632cf43fd6d1f8b8f40a88892a45b6bfad6e.zip
glibc-9835632cf43fd6d1f8b8f40a88892a45b6bfad6e.tar.gz
glibc-9835632cf43fd6d1f8b8f40a88892a45b6bfad6e.tar.bz2
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.
-rw-r--r--malloc/hooks.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/malloc/hooks.c b/malloc/hooks.c
index 6474ba8..fc285f1 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -260,6 +260,8 @@ free_check (void *mem, const void *caller)
if (!mem)
return;
+ int err = errno;
+
#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
@@ -274,12 +276,16 @@ free_check (void *mem, const void *caller)
{
__libc_lock_unlock (main_arena.mutex);
munmap_chunk (p);
- return;
}
- /* Mark the chunk as belonging to the library again. */
- (void)TAG_REGION (chunk2rawmem (p), CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
- _int_free (&main_arena, p, 1);
- __libc_lock_unlock (main_arena.mutex);
+ else
+ {
+ /* Mark the chunk as belonging to the library again. */
+ (void)TAG_REGION (chunk2rawmem (p), CHUNK_AVAILABLE_SIZE (p)
+ - CHUNK_HDR_SZ);
+ _int_free (&main_arena, p, 1);
+ __libc_lock_unlock (main_arena.mutex);
+ }
+ __set_errno (err);
}
static void *