From c74c36333b33452a27f5da428c1087a547c2170b Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 2 Nov 2023 23:25:57 +0000 Subject: 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). --- lib/heap.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') 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 + 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; } -- cgit v1.2.3-13-gbd6f