From 85ea66932e0ae3e5dce36aa001d3f363218344ad Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Fri, 13 Aug 2021 12:42:02 +0200 Subject: [PATCH] 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. --- Kernel/Heap/kmalloc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Kernel/Heap/kmalloc.h b/Kernel/Heap/kmalloc.h index f7af78577b..5aa0e21a31 100644 --- a/Kernel/Heap/kmalloc.h +++ b/Kernel/Heap/kmalloc.h @@ -93,6 +93,8 @@ template inline void kfree_aligned(void* ptr) { + if (ptr == nullptr) + return; kfree((u8*)ptr - ((const ptrdiff_t*)ptr)[-1]); }