Skip to content

Commit

Permalink
Remove redundant null pointer check in operator delete
Browse files Browse the repository at this point in the history
Summary:
C89 4.10.3.2 The free function
C99 7.20.3.2 The free function
C11 7.22.3.3 The free function

    If ptr is a null pointer, no action shall occur.

_aligned_free on MSDN:

    If memblock is a NULL pointer, this function simply performs no actions.

Reviewers: EricWF, mclow.lists, khng300, hotpxl

Reviewed By: mclow.lists, khng300, hotpxl

Subscribers: lichray, llvm-commits, hotpxl, khng300, christof, ldionne, cfe-commits, libcxx-commits

Differential Revision: https://reviews.llvm.org/D52401

llvm-svn: 343503
  • Loading branch information
MaskRay committed Oct 1, 2018
1 parent 23b62aa commit 7cd6790
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions libcxx/src/new.cpp
Expand Up @@ -135,8 +135,7 @@ _LIBCPP_WEAK
void
operator delete(void* ptr) _NOEXCEPT
{
if (ptr)
::free(ptr);
::free(ptr);
}

_LIBCPP_WEAK
Expand Down Expand Up @@ -257,11 +256,10 @@ _LIBCPP_WEAK
void
operator delete(void* ptr, std::align_val_t) _NOEXCEPT
{
if (ptr)
#if defined(_LIBCPP_MSVCRT_LIKE)
::_aligned_free(ptr);
::_aligned_free(ptr);
#else
::free(ptr);
::free(ptr);
#endif
}

Expand Down

0 comments on commit 7cd6790

Please sign in to comment.