summaryrefslogtreecommitdiff
path: root/src/kernel/mem
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/mem')
-rw-r--r--src/kernel/mem/alloc.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/kernel/mem/alloc.c b/src/kernel/mem/alloc.c
index 59898cb..132ab24 100644
--- a/src/kernel/mem/alloc.c
+++ b/src/kernel/mem/alloc.c
@@ -48,12 +48,16 @@ void *kmalloc(size_t len) {
}
void kfree(void *ptr) {
+ uint32_t *magic = &((uint32_t*)ptr)[-1];
if (ptr == NULL) return;
- if (((uint32_t*)ptr)[-1] != MALLOC_MAGIC) {
+ if (*magic != MALLOC_MAGIC) {
// TODO add some kind of separate system log
tty_const("WARNING kfree() didn't find MALLOC_MAGIC, ptr == ");
_tty_var(ptr);
tty_const(" ");
+ } else {
+ // change the magic marker to detect double frees
+ *magic = 0xBADF2EED;
}
malloc_balance--;
}