summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authordzwdz2023-02-22 14:38:56 +0100
committerdzwdz2023-02-22 14:38:56 +0100
commit5715a511fcd0490dfc74579ee95f88ef1877f021 (patch)
tree9b438651724773caae2f4aa70fdcb8cbd5076024 /src/kernel
parentd94b4c18741cd081d1ef3a8ff6345034c0a6782b (diff)
kernel/malloc: fill allocated and freed regions with junk
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/malloc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/kernel/malloc.c b/src/kernel/malloc.c
index 8c52b6f..0cfcc68 100644
--- a/src/kernel/malloc.c
+++ b/src/kernel/malloc.c
@@ -155,12 +155,16 @@ void *kmalloc(size_t len) {
malloc_last = hdr;
addr = (void*)hdr + sizeof(struct malloc_hdr);
+#ifndef NDEBUG
+ memset(addr, 0xCC, len);
+#endif
kmalloc_sanity(addr);
return addr;
}
void kfree(void *ptr) {
struct malloc_hdr *hdr;
+ uint32_t page_amt;
if (ptr == NULL) return;
hdr = ptr - sizeof(struct malloc_hdr);
@@ -173,5 +177,9 @@ void kfree(void *ptr) {
hdr->prev->next = hdr->next;
if (malloc_last == hdr)
malloc_last = hdr->prev;
- page_free(hdr, hdr->page_amt);
+ page_amt = hdr->page_amt;
+#ifndef NDEBUG
+ memset(hdr, 0xC0, page_amt * PAGE_SIZE);
+#endif
+ page_free(hdr, page_amt);
}