From 5715a511fcd0490dfc74579ee95f88ef1877f021 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 22 Feb 2023 14:38:56 +0100 Subject: kernel/malloc: fill allocated and freed regions with junk --- src/kernel/malloc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/kernel') 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); } -- cgit v1.2.3