From cc3b6f3a05b882a507d39a83a4fcc8280d3ecb42 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 21 Sep 2008 21:25:58 +0000 Subject: [PATCH] malloc() now also logs an error when a request could not be served. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27677 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/boot/loader/heap.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/system/boot/loader/heap.cpp b/src/system/boot/loader/heap.cpp index fdb28d240b..1bd7808187 100644 --- a/src/system/boot/loader/heap.cpp +++ b/src/system/boot/loader/heap.cpp @@ -22,7 +22,7 @@ * linked list). * When memory is allocated, the smallest free chunk that contains * the requested size is split (or taken as a whole if it can't be - * splitted anymore), and it's lower half will be removed from the + * splitted anymore), and it's lower half will be removed from the * free list. * The free list is ordered by size, starting with the smallest * free chunk available. When a chunk is freed, it will be joint @@ -117,7 +117,7 @@ free_chunk::Join(free_chunk *chunk) } -void +void free_chunk::Remove(free_chunk *previous) { if (previous == NULL) { @@ -138,7 +138,7 @@ free_chunk::Remove(free_chunk *previous) } -void +void free_chunk::Enqueue() { free_chunk *chunk = sFreeAnchor.next, *last = &sFreeAnchor; @@ -252,8 +252,10 @@ malloc(size_t size) // align the size requirement to a 4 bytes boundary size = (size + 3) & 0xfffffffc; - if (size > sAvailable) + if (size > sAvailable) { + dprintf("malloc(): Out of memory!\n"); return NULL; + } free_chunk *chunk = sFreeAnchor.next, *last = &sFreeAnchor; while (chunk && chunk->Size() < size) { @@ -263,6 +265,7 @@ malloc(size_t size) if (chunk == NULL) { // could not find a free chunk as large as needed + dprintf("malloc(): Out of memory!\n"); return NULL; } @@ -356,7 +359,7 @@ free(void *allocated) // remove the joined chunk from the list last->next = freedChunk->next; chunk = last; - + if (++joinCount == 2) break; } @@ -365,7 +368,7 @@ free(void *allocated) chunk = chunk->next; } - // enqueue the link at the right position; the + // enqueue the link at the right position; the // free link queue is ordered by size freedChunk->Enqueue();