From 08d4be67992784b5dd04e5aaad8248a0dd54b08b Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Fri, 18 Oct 2002 04:19:57 +0000 Subject: Don't infinitely recurse when trying to grow __malloc_mmb_heap. --- libc/stdlib/malloc/malloc.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'libc') diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c index 25fda4115..b23d566b1 100644 --- a/libc/stdlib/malloc/malloc.c +++ b/libc/stdlib/malloc/malloc.c @@ -118,11 +118,25 @@ malloc_from_heap (size_t size, struct heap *heap) if (likely (block != (void *)-1)) { #if !defined(MALLOC_USE_SBRK) && defined(__UCLIBC_UCLINUX_BROKEN_MUNMAP__) - struct malloc_mmb *mmb, *prev_mmb; - struct malloc_mmb *new_mmb - = malloc_from_heap (sizeof *new_mmb, &__malloc_mmb_heap); + struct malloc_mmb *mmb, *prev_mmb, *new_mmb; +#endif + + MALLOC_DEBUG (" adding memory: 0x%lx - 0x%lx (%d bytes)\n", + (long)block, (long)block + block_size, block_size); + + /* Get back the heap lock. */ + __heap_lock (heap); + + /* Put BLOCK into the heap. */ + __heap_free (heap, block, block_size); + + /* Try again to allocate. */ + mem = __heap_alloc (heap, &size); + + __heap_unlock (heap); - /* Insert a record of this allocation in sorted order into the +#if !defined(MALLOC_USE_SBRK) && defined(__UCLIBC_UCLINUX_BROKEN_MUNMAP__) + /* Insert a record of BLOCK in sorted order into the __malloc_mmapped_blocks list. */ for (prev_mmb = 0, mmb = __malloc_mmapped_blocks; @@ -131,6 +145,7 @@ malloc_from_heap (size_t size, struct heap *heap) if (block < mmb->mem) break; + new_mmb = malloc_from_heap (sizeof *new_mmb, &__malloc_mmb_heap); new_mmb->next = mmb; new_mmb->mem = block; new_mmb->size = block_size; @@ -144,20 +159,6 @@ malloc_from_heap (size_t size, struct heap *heap) (unsigned)new_mmb, (unsigned)new_mmb->mem, block_size); #endif /* !MALLOC_USE_SBRK && __UCLIBC_UCLINUX_BROKEN_MUNMAP__ */ - - MALLOC_DEBUG (" adding memory: 0x%lx - 0x%lx (%d bytes)\n", - (long)block, (long)block + block_size, block_size); - - /* Get back the heap lock. */ - __heap_lock (heap); - - /* Put BLOCK into the heap. */ - __heap_free (heap, block, block_size); - - /* Try again to allocate. */ - mem = __heap_alloc (heap, &size); - - __heap_unlock (heap); } } -- cgit v1.2.3