Kernel: Allow kfree_aligned to be called on null pointers

The C++ standard specifies that `free` and `operator delete` should
be callable with nullptr. The non-aligned `kfree` already handles this,
but because of the pointer arithmetic to obtain the allocation start
pointer, the aligned version would produce undefined behavior.
This commit is contained in:
Daniel Bertalan 2021-08-13 12:42:02 +02:00 committed by Andreas Kling
parent 5c7524b1d8
commit 85ea66932e
Notes: sideshowbarker 2024-07-18 07:00:52 +09:00

View File

@ -93,6 +93,8 @@ template<size_t ALIGNMENT>
inline void kfree_aligned(void* ptr)
{
if (ptr == nullptr)
return;
kfree((u8*)ptr - ((const ptrdiff_t*)ptr)[-1]);
}