summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--page.c14
1 files 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) {