mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-03 04:50:29 +00:00
Kernel: Allow passing null pointer to delete
The C++ standard says that it's legal to call the `delete` operator with a null pointer argument, in which case it should be a no-op. I encountered this issue when running a kernel that's compiled with Clang. I assume this fact was used for some kind of optimization.
This commit is contained in:
parent
bb26cea291
commit
b847541ee8
Notes:
sideshowbarker
2024-07-18 09:04:55 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/b847541ee85 Pull-request: https://github.com/SerenityOS/serenity/pull/8696 Reviewed-by: https://github.com/Dexesttp Reviewed-by: https://github.com/gunnarbeutner ✅ Reviewed-by: https://github.com/networkException
2 changed files with 4 additions and 0 deletions
|
@ -33,6 +33,8 @@ public: \
|
|||
} \
|
||||
void operator delete(void* ptr) noexcept \
|
||||
{ \
|
||||
if (!ptr) \
|
||||
return; \
|
||||
slab_dealloc(ptr, sizeof(type)); \
|
||||
} \
|
||||
\
|
||||
|
|
|
@ -59,6 +59,8 @@ OwnPtr<KString> KString::try_clone() const
|
|||
|
||||
void KString::operator delete(void* string)
|
||||
{
|
||||
if (!string)
|
||||
return;
|
||||
size_t allocation_size = sizeof(KString) + (sizeof(char) * static_cast<KString*>(string)->m_length) + sizeof(char);
|
||||
kfree_sized(string, allocation_size);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue