Skip to content

Commit

Permalink
Fix sized delete of nullptr (microsoft#181)
Browse files Browse the repository at this point in the history
* Fix sized delete of nullptr

The core snmalloc code assumes if you know the size, then it is not
nullptr. However, the C++ delete operator can be called with nullptr.

This change checks for that case.
  • Loading branch information
mjp41 authored May 7, 2020
1 parent a9cfc3a commit 4347701
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/override/new.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void operator delete(void* p)EXCEPTSPEC

void operator delete(void* p, size_t size)EXCEPTSPEC
{
if (p == nullptr)
return;
ThreadAlloc::get_noncachable()->dealloc(p, size);
}

Expand All @@ -58,6 +60,8 @@ void operator delete[](void* p) EXCEPTSPEC

void operator delete[](void* p, size_t size) EXCEPTSPEC
{
if (p == nullptr)
return;
ThreadAlloc::get_noncachable()->dealloc(p, size);
}

Expand Down

0 comments on commit 4347701

Please sign in to comment.