mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Kernel: Add some basic double-kfree() detection
Double kfree() is exceedingly rare in our kernel since we use automatic memory management and smart pointers for almost all code. However, it doesn't hurt to do some basic checking that might one day catch bugs. This patch makes us VERIFY that we don't already consider the first chunk of a kmalloc() allocation free when kfree()'ing it.
This commit is contained in:
parent
fa9f5c9799
commit
79ebcacce2
1 changed files with 4 additions and 1 deletions
|
@ -107,9 +107,12 @@ public:
|
|||
return;
|
||||
auto* a = (AllocationHeader*)((((u8*)ptr) - sizeof(AllocationHeader)));
|
||||
VERIFY((u8*)a >= m_chunks && (u8*)ptr < m_chunks + m_total_chunks * CHUNK_SIZE);
|
||||
VERIFY((u8*)a + a->allocation_size_in_chunks * CHUNK_SIZE <= m_chunks + m_total_chunks * CHUNK_SIZE);
|
||||
FlatPtr start = ((FlatPtr)a - (FlatPtr)m_chunks) / CHUNK_SIZE;
|
||||
|
||||
// First, verify that the start of the allocation at `ptr` is actually allocated.
|
||||
VERIFY(m_bitmap.get(start));
|
||||
|
||||
VERIFY((u8*)a + a->allocation_size_in_chunks * CHUNK_SIZE <= m_chunks + m_total_chunks * CHUNK_SIZE);
|
||||
m_bitmap.set_range(start, a->allocation_size_in_chunks, false);
|
||||
|
||||
VERIFY(m_allocated_chunks >= a->allocation_size_in_chunks);
|
||||
|
|
Loading…
Add table
Reference in a new issue