diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-02 23:25:57 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-02 23:25:57 +0000 |
commit | c74c36333b33452a27f5da428c1087a547c2170b (patch) | |
tree | 02c57944744efe5b64545cddaee2e7d46613d647 | |
parent | f433febb2215dc343ab1fb40edca6380581554a3 (diff) | |
download | ovm-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).
-rw-r--r-- | lib/heap.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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; } |