From 7d602faf7652cbd8358ff90a9eaa53ac5230dabe Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 28 Oct 2008 06:48:06 +0000 Subject: Finally fix the MALLOC=y and MALLOC_SIMPLE=y breakage from svn 23660. (I found it, this is Bernhard's patch to fix it. Tested and it Works For Me (tm)). --- libc/stdlib/malloc/free.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'libc/stdlib/malloc/free.c') diff --git a/libc/stdlib/malloc/free.c b/libc/stdlib/malloc/free.c index 4713b0624..91552919e 100644 --- a/libc/stdlib/malloc/free.c +++ b/libc/stdlib/malloc/free.c @@ -21,12 +21,18 @@ libc_hidden_proto(sbrk) #include "malloc.h" #include "heap.h" -static void #ifdef HEAP_USE_LOCKING -free_to_heap (void *mem, struct heap_free_area *heap, malloc_mutex_t *heap_lock) +#define free_to_heap(mem, heap, lck) __free_to_heap(mem, heap, lck) #else -free_to_heap (void *mem, struct heap_free_area *heap) +#define free_to_heap(mem, heap, lck) __free_to_heap(mem, heap) +#endif + +static void +__free_to_heap (void *mem, struct heap_free_area **heap +#ifdef HEAP_USE_LOCKING + , malloc_mutex_t *heap_lock #endif + ) { size_t size; struct heap_free_area *fa; @@ -43,7 +49,7 @@ free_to_heap (void *mem, struct heap_free_area *heap) size = MALLOC_SIZE (mem); mem = MALLOC_BASE (mem); - __heap_do_lock (heap_lock); + __heap_lock (heap_lock); /* Put MEM back in the heap, and get the free-area it was placed in. */ fa = __heap_free (heap, mem, size); @@ -52,7 +58,7 @@ free_to_heap (void *mem, struct heap_free_area *heap) unmapped. */ if (HEAP_FREE_AREA_SIZE (fa) < MALLOC_UNMAP_THRESHOLD) /* Nope, nothing left to do, just release the lock. */ - __heap_do_unlock (heap_lock); + __heap_unlock (heap_lock); else /* Yup, try to unmap FA. */ { @@ -85,7 +91,7 @@ free_to_heap (void *mem, struct heap_free_area *heap) MALLOC_DEBUG (-1, "not unmapping: 0x%lx - 0x%lx (%ld bytes)", start, end, end - start); __malloc_unlock_sbrk (); - __heap_do_unlock (heap_lock); + __heap_unlock (heap_lock); return; } #endif @@ -102,7 +108,7 @@ free_to_heap (void *mem, struct heap_free_area *heap) another free area, even if it's smaller than MALLOC_MIN_SIZE, will cause us not to reserve anything. */ { - /* Put the reserved memory back in the heap; we asssume that + /* Put the reserved memory back in the heap; we assume that MALLOC_UNMAP_THRESHOLD is greater than MALLOC_MIN_SIZE, so we use the latter unconditionally here. */ __heap_free (heap, (void *)start, MALLOC_MIN_SIZE); @@ -112,7 +118,7 @@ free_to_heap (void *mem, struct heap_free_area *heap) #ifdef MALLOC_USE_SBRK /* Release the heap lock; we're still holding the sbrk lock. */ - __heap_do_unlock (heap_lock); + __heap_unlock (heap_lock); /* Lower the brk. */ sbrk (start - end); /* Release the sbrk lock too; now we hold no locks. */ @@ -176,20 +182,15 @@ free_to_heap (void *mem, struct heap_free_area *heap) /* We have to unlock the heap before we recurse to free the mmb descriptor, because we might be unmapping from the mmb heap. */ - __heap_do_unlock (heap_lock); + __heap_unlock (heap_lock); -#ifdef HEAP_USE_LOCKING /* Release the descriptor block we used. */ free_to_heap (mmb, &__malloc_mmb_heap, &__malloc_mmb_heap_lock); -#else - /* Release the descriptor block we used. */ - free_to_heap (mmb, &__malloc_mmb_heap); -#endif /* Do the actual munmap. */ munmap ((void *)mmb_start, mmb_end - mmb_start); - __heap_do_lock (heap_lock); + __heap_lock (heap_lock); # ifdef __UCLIBC_HAS_THREADS__ /* In a multi-threaded program, it's possible that PREV_MMB has @@ -222,7 +223,7 @@ free_to_heap (void *mem, struct heap_free_area *heap) } /* Finally release the lock for good. */ - __heap_do_unlock (heap_lock); + __heap_unlock (heap_lock); MALLOC_MMB_DEBUG_INDENT (-1); @@ -252,7 +253,7 @@ free_to_heap (void *mem, struct heap_free_area *heap) } /* Release the heap lock before we do the system call. */ - __heap_do_unlock (heap_lock); + __heap_unlock (heap_lock); if (unmap_end > unmap_start) /* Finally, actually unmap the memory. */ @@ -269,9 +270,5 @@ free_to_heap (void *mem, struct heap_free_area *heap) void free (void *mem) { -#ifdef HEAP_USE_LOCKING - free_to_heap (mem, __malloc_heap, &__malloc_heap_lock); -#else - free_to_heap (mem, __malloc_heap); -#endif + free_to_heap (mem, &__malloc_heap, &__malloc_heap_lock); } -- cgit v1.2.3