From 54711c1b89ab218c7f039c051f06abb36879bc1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 18 Aug 2003 03:35:57 +0000 Subject: [PATCH] free() now fills the freed memory with 0xdeadbeef if PARANOID_KFREE is defined (except for the first 4 bytes, because that's the pointer to the next buffer in the free list). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4299 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/heap.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/kernel/core/heap.c b/src/kernel/core/heap.c index f4d731f834..2a885c2147 100644 --- a/src/kernel/core/heap.c +++ b/src/kernel/core/heap.c @@ -27,7 +27,7 @@ #define PARANOID_POINTER_CHECK 1 /* initialize newly allocated memory with something non zero */ #define PARANOID_KMALLOC 1 -/* check if freed pointers are already freed */ +/* check if freed pointers are already freed, and fill freed memory with 0xdeadbeef */ #define PARANOID_KFREE 1 /* use a back and front wall around each allocation */ /* does currently not work correctly, because the VM malloc()s a PAGE_SIZE and @@ -375,6 +375,19 @@ free(void *address) if (bin->element_size <= PAGE_SIZE && (addr)address % bin->element_size != 0) panic("kfree: passed invalid pointer %p! Supposed to be in bin for esize 0x%x\n", address, bin->element_size); +#if PARANOID_KFREE + // mark the free space as freed + { + uint32 deadbeef = 0xdeadbeef; + uint8 *dead = (uint8 *)address; + int32 i; + + // the first 4 bytes are overwritten with the next free list pointer later + for (i = 4; i < bin->element_size; i++) + dead[i] = ((uint8 *)&deadbeef)[i % 4]; + } +#endif + for (i = 0; i < bin->element_size / PAGE_SIZE; i++) { if (page[i].bin_index != page[0].bin_index) panic("free(): not all pages in allocation match bin_index\n");