瀏覽代碼

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.
Daniel Bertalan 4 年之前
父節點
當前提交
85ea66932e
共有 1 個文件被更改,包括 2 次插入0 次删除
  1. 2 0
      Kernel/Heap/kmalloc.h

+ 2 - 0
Kernel/Heap/kmalloc.h

@@ -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]);
 }