libluna/Heap: Crash the kernel (but not userspace) on invalid frees

This makes them way easier to catch and forces us to get those out of the way.
This commit is contained in:
apio 2023-03-10 21:02:09 +01:00
parent c376477080
commit e8a401efc2
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -249,13 +249,21 @@ Result<void> free_impl(void* ptr)
else
dbgln("ERROR: Attempt to free memory at %p, which wasn't allocated with malloc", ptr);
#ifdef USE_FREESTANDING
fail("Call to free_impl() with an invalid argument (double-free or erroneous deallocation)");
#else
return err(EFAULT);
#endif
}
if (is_block_free(block))
{
dbgln("ERROR: Attempt to free memory at %p, which was already freed", ptr);
#ifdef USE_FREESTANDING
fail("Call to free_impl() with a pointer to freed memory (probably double-free)");
#else
return err(EFAULT);
#endif
}
else
block->status &= ~BLOCK_USED;