aboutsummaryrefslogtreecommitdiff
path: root/lib/heap.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-02 23:25:57 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-02 23:25:57 +0000
commitc74c36333b33452a27f5da428c1087a547c2170b (patch)
tree02c57944744efe5b64545cddaee2e7d46613d647 /lib/heap.c
parentf433febb2215dc343ab1fb40edca6380581554a3 (diff)
downloadovm-c74c36333b33452a27f5da428c1087a547c2170b.tar.gz
ovm-c74c36333b33452a27f5da428c1087a547c2170b.tar.bz2
ovm-c74c36333b33452a27f5da428c1087a547c2170b.zip
Fixed bug where deleting a page meant not being able to allocate another
This was due to the beg or end page being not set correctly (dangling pointer).
Diffstat (limited to 'lib/heap.c')
-rw-r--r--lib/heap.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/heap.c b/lib/heap.c
index 7dd7a12..28cb06a 100644
--- a/lib/heap.c
+++ b/lib/heap.c
@@ -12,6 +12,8 @@
#include "./heap.h"
+#include <stdio.h>
+
page_t *page_create(size_t max, page_t *next)
{
page_t *page = calloc(1, sizeof(*page) + max);
@@ -41,6 +43,8 @@ bool heap_free_page(heap_t *heap, page_t *page)
heap->beg = heap->beg->next;
page_delete(page);
--heap->pages;
+ if (heap->pages == 0)
+ heap->end = NULL;
return true;
}
@@ -63,6 +67,8 @@ bool heap_free_page(heap_t *heap, page_t *page)
heap->end = prev;
page_delete(page);
--heap->pages;
+ if (heap->pages == 0)
+ heap->beg = NULL;
return true;
}