summaryrefslogtreecommitdiffstats
path: root/heap.c
diff options
context:
space:
mode:
Diffstat (limited to 'heap.c')
-rw-r--r--heap.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/heap.c b/heap.c
index a57a45d..777be78 100644
--- a/heap.c
+++ b/heap.c
@@ -157,8 +157,11 @@ __heap_bucket_append(struct heap *heap, struct bucket *bucket, size_t size)
if(free->next != NULL) free->next->prev = free;
bucket->next = free;
- /*Fix heap buckets_head*/
- if(free->next == NULL) heap->buckets_head = free;
+ /*Mark up to head used memory*/
+ if(free->next == NULL) {
+ heap->used += bestfit->sizetaken;
+ heap->buckets_head = free;
+ }
/*Populate free bucket*/
free->address = bucket->address + bucket->sizetaken;
@@ -258,8 +261,6 @@ heap_alloc(struct heap *heap, size_t size)
/*Split bucket into perfectly sized piece*/
__heap_bucket_split(heap, bestfit, size);
- /*Take memory in heap, mark bucket as taken*/
- heap->used += bestfit->sizetaken;
bestfit->sizetaken |= 1;
return (void*)bestfit->address;
}