summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorMiles Bader <miles@lsi.nec.co.jp>2002-10-18 04:19:57 +0000
committerMiles Bader <miles@lsi.nec.co.jp>2002-10-18 04:19:57 +0000
commit08d4be67992784b5dd04e5aaad8248a0dd54b08b (patch)
treef6a7570f5c94d06cb95ae3536ee86478d6062f36 /libc
parent6343d9e51dff0b86bd5b6d9f6aca2e155aba5549 (diff)
Don't infinitely recurse when trying to grow __malloc_mmb_heap.
Diffstat (limited to 'libc')
-rw-r--r--libc/stdlib/malloc/malloc.c37
1 files changed, 19 insertions, 18 deletions
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);
}
}