From 6882d43363b5411a16657378b2f8110988dd9660 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Tue, 15 Oct 2002 02:15:16 +0000 Subject: Fix locking to not deadlock when __UCLIBC_UCLINUX_BROKEN_MUNMAP__ is defined. --- libc/stdlib/malloc/free.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'libc/stdlib/malloc/free.c') diff --git a/libc/stdlib/malloc/free.c b/libc/stdlib/malloc/free.c index 6c3211360..a00f996d9 100644 --- a/libc/stdlib/malloc/free.c +++ b/libc/stdlib/malloc/free.c @@ -105,7 +105,7 @@ free_to_heap (void *mem, struct heap *heap) #ifdef MALLOC_USE_SBRK - /* Release the main lock; we're still holding the sbrk lock. */ + /* Release the heap lock; we're still holding the sbrk lock. */ __heap_unlock (heap); /* Lower the brk. */ sbrk (start - end); @@ -161,16 +161,21 @@ free_to_heap (void *mem, struct heap *heap) else __malloc_mmapped_blocks = next_mmb; + /* Start searching again from the end of this block. */ + start = mmb_end; + + /* We have to unlock the heap before we recurse to free the mmb + descriptor, because we might be unmapping from the mmb + heap. */ + __heap_unlock (heap); + /* Release the descriptor block we used. */ free_to_heap (mmb, &__malloc_mmb_heap); /* Do the actual munmap. */ - __heap_unlock (heap); munmap ((void *)mmb_start, mmb_end - mmb_start); - __heap_lock (heap); - /* Start searching again from the end of that block. */ - start = mmb_end; + __heap_lock (heap); # ifdef __UCLIBC_HAS_THREADS__ /* In a multi-threaded program, it's possible that PREV_MMB has -- cgit v1.2.3