diff --git a/headers/private/kernel/util/SimpleAllocator.h b/headers/private/kernel/util/SimpleAllocator.h index df2a5be6ac..1221c56974 100644 --- a/headers/private/kernel/util/SimpleAllocator.h +++ b/headers/private/kernel/util/SimpleAllocator.h @@ -266,6 +266,9 @@ public: #ifdef DEBUG_MAX_HEAP_USAGE fMaxHeapUsage = std::max(fMaxHeapUsage, fMaxHeapSize - fAvailable); #endif +#ifdef DEBUG_ALLOCATIONS + memset(allocated, 0xcc, chunk->Size()); +#endif return allocated; } @@ -306,7 +309,7 @@ public: FreeChunk* freedChunk = FreeChunk::SetToAllocated(allocated); -#ifdef DEBUG_ALLOCATIONS +#ifdef DEBUG_VALIDATE_HEAP_ON_FREE if (freedChunk->Size() > (fMaxHeapSize - fAvailable)) { panic("freed chunk %p clobbered (%#zx)!\n", freedChunk, freedChunk->Size()); @@ -321,6 +324,10 @@ public: } } #endif +#ifdef DEBUG_ALLOCATIONS + for (uint32 i = 0; i < (freedChunk->Size() / 4); i++) + ((uint32*)allocated)[i] = 0xdeadbeef; +#endif // try to join the new free chunk with an existing one // it may be joined with up to two chunks diff --git a/src/system/boot/loader/heap.cpp b/src/system/boot/loader/heap.cpp index 9fbd1e8436..043be1395e 100644 --- a/src/system/boot/loader/heap.cpp +++ b/src/system/boot/loader/heap.cpp @@ -16,11 +16,16 @@ #include +#if KDEBUG #define DEBUG_ALLOCATIONS - // if defined, freed memory is filled with 0xcc + // if defined, allocated memory is filled with 0xcc and freed memory with 0xdeadbeef #define DEBUG_MAX_HEAP_USAGE // if defined, the maximum heap usage is determined and printed before // entering the kernel +#define DEBUG_VALIDATE_HEAP_ON_FREE + // if defined, the heap integrity is checked on every free + // (must have DEBUG_MAX_HEAP_USAGE defined also) +#endif #include