summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
}
}