public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/lld] malloc: preserve errno on mcheck hooks [BZ #17924]
@ 2021-01-18 21:36 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-01-18 21:36 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9835632cf43fd6d1f8b8f40a88892a45b6bfad6e

commit 9835632cf43fd6d1f8b8f40a88892a45b6bfad6e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Dec 29 17:12:21 2020 -0300

    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.

Diff:
---
 malloc/hooks.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/malloc/hooks.c b/malloc/hooks.c
index 6474ba8b38..fc285f15c6 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 *


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-18 21:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18 21:36 [glibc/maskray/lld] malloc: preserve errno on mcheck hooks [BZ #17924] Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).