summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2024-06-26 00:01:23 -0500
committerDanny Holman <dholman@gymli.org>2024-06-26 00:01:23 -0500
commit5e166f3042a8e7b3031aae4da7006f80caa53ecc (patch)
treecdb1837d8e3a9bbcfabe147da78c4c3e43cce7d8
parente8a8e23a8543224be42798b4c357df67ef30b6f5 (diff)
arch: i386: kmalloc: fix last element being ignoredHEADmaster
Fix a bug in kmalloc in which the last element of the mem_block linked list would be ignored and potentially overwritten. Signed-off-by: Danny Holman <dholman@gymli.org>
-rw-r--r--arch/i386/kernel/kmalloc.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/arch/i386/kernel/kmalloc.c b/arch/i386/kernel/kmalloc.c
index 9c82e39..ea77428 100644
--- a/arch/i386/kernel/kmalloc.c
+++ b/arch/i386/kernel/kmalloc.c
@@ -37,9 +37,9 @@ void* kmalloc(size_t sz) {
struct mem_block *temp = first;
while (temp->next != NULL) {
- if (temp->size <= sz && temp->alloc == 0) {
- temp->alloc = 1;
- return (void*)temp->start;
+ if (temp->next->size <= sz && temp->next->alloc == 0) {
+ temp->next->alloc = 1;
+ return (void*)temp->next->start;
}
temp = temp->next;
}
@@ -48,11 +48,10 @@ void* kmalloc(size_t sz) {
if (temp->next > kbrk)
_request_page();
temp->next->prev = temp;
- temp = temp->next;
- temp->start = (uintptr_t)(temp + sizeof(struct mem_block));
- temp->size = sz;
- temp->alloc = 1;
- temp->next = NULL;
+ temp->next->start = (uintptr_t)(temp->next + sizeof(struct mem_block));
+ temp->next->size = sz;
+ temp->next->alloc = 1;
+ temp->next->next = NULL;
return (void*)temp->start;
}