diff --git a/libluna/src/Heap.cpp b/libluna/src/Heap.cpp index 8c7e9fdf..c989eaec 100644 --- a/libluna/src/Heap.cpp +++ b/libluna/src/Heap.cpp @@ -249,13 +249,21 @@ Result 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;