summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authordzwdz2021-09-22 20:28:50 +0200
committerdzwdz2021-09-22 20:28:50 +0200
commit1ae9c4e79f2fa1f44ccad464338542558780a48d (patch)
treeb85da8e81d7931abc5edb7bc20460711cfac0108 /src/kernel
parente0d5bd7c68d862206318e5b277feea9cb11b3995 (diff)
kfree: detect double frees
Diffstat (limited to 'src/kernel')
-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--;
}