From 460b0be997fac5e0760d7c57c92fc287d45450e4 Mon Sep 17 00:00:00 2001 From: Ry Date: Tue, 11 Jul 2023 23:37:11 -0700 Subject: [PATCH] kernel/allocator: FINALLY fix a long-standing bug with memory freeing This fixes issue #7 --- kernel/allocator.asm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/allocator.asm b/kernel/allocator.asm index 1b03cc2..d3e261f 100644 --- a/kernel/allocator.asm +++ b/kernel/allocator.asm @@ -41,6 +41,8 @@ allocate_memory: push r11 mov [block], [free_list_head] + cmp [block], 0 + ifz jmp allocate_memory_bad ; r10: real_size = requested size + header size mov r10, r0 @@ -58,6 +60,7 @@ allocate_memory_while_block: cmp [block], 0 ifnz jmp allocate_memory_while_block +allocate_memory_bad: ; if we reach this point, no good blocks were found mov r0, 0 @@ -177,7 +180,7 @@ free_memory: call block_set_next cmp [free_list_head], 0 - ifnz mov r1, r0 + ifnz mov r1, r2 ifnz mov r0, [free_list_head] ifnz call block_set_prev