diff mbox series

malloc: Add lock to heap consistency check

Message ID 1569325132-22320-2-git-send-email-oftedal@gmail.com
State New
Headers show
Series malloc: Add lock to heap consistency check | expand

Commit Message

Kjetil Oftedal Sept. 24, 2019, 11:38 a.m. UTC
The heap consitency check was unprotected leading to false heap errors
being reported in multithreaded applications.

Signed-off-by: Kjetil Oftedal <oftedal@gmail.com>
---
 libc/stdlib/malloc/malloc.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index f6bf10a..485aac3 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -204,8 +204,11 @@  malloc (size_t size)
       debugging_initialized = 1;
       __malloc_debug_init ();
     }
-  if (__malloc_check)
+  if (__malloc_check) {
+	__heap_lock (&__malloc_heap_lock);
     __heap_check (__malloc_heap, "malloc");
+	__heap_unlock (&__malloc_heap_lock);
+  }
 #endif
 
 #ifdef __MALLOC_GLIBC_COMPAT__