From 7e9998311d5d5c657ea2a15091382c23ffeecd3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 20 Apr 2020 00:31:15 -0300 Subject: Move page pointer on free When freeing a page, its pointer will move to the previous page if available. If not it will move to the next page. --- page.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/page.c b/page.c index a41f2d5..fd4ae6e 100644 --- a/page.c +++ b/page.c @@ -42,14 +42,16 @@ void split_page(struct page *first_half) { first_half->next = second_half; } -void free_page(struct page *page) { - if (page->next) { - page->next->prev = page->prev; +void free_page(struct page **page) { + if ((*page)->prev) { + (*page)->prev->next = (*page)->next; } - if (page->prev) { - page->prev->next = page->next; + if ((*page)->next) { + (*page)->next->prev = (*page)->prev; } - free(page); + struct page *tmp = *page; + *page = (*page)->prev ?: (*page)->next; + free(tmp); } void move_gap(struct page *page, int target) { -- cgit v1.2.3