summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jemalloc_cpp.cpp6
-rw-r--r--test/integration/cpp/basic.cpp10
2 files changed, 16 insertions, 0 deletions
diff --git a/src/jemalloc_cpp.cpp b/src/jemalloc_cpp.cpp
index 5cecfdb..984c944 100644
--- a/src/jemalloc_cpp.cpp
+++ b/src/jemalloc_cpp.cpp
@@ -118,11 +118,17 @@ void operator delete[](void *ptr, const std::nothrow_t &) noexcept
void
operator delete(void *ptr, std::size_t size) noexcept
{
+ if (unlikely(ptr == nullptr)) {
+ return;
+ }
je_sdallocx(ptr, size, /*flags=*/0);
}
void operator delete[](void *ptr, std::size_t size) noexcept
{
+ if (unlikely(ptr == nullptr)) {
+ return;
+ }
je_sdallocx(ptr, size, /*flags=*/0);
}
diff --git a/test/integration/cpp/basic.cpp b/test/integration/cpp/basic.cpp
index 4a87a3b..b208e1d 100644
--- a/test/integration/cpp/basic.cpp
+++ b/test/integration/cpp/basic.cpp
@@ -6,6 +6,16 @@ TEST_BEGIN(test_basic)
auto foo = new long(4);
assert_ptr_not_null(foo, "Unexpected new[] failure");
delete foo;
+ // Test nullptr handling.
+ foo = nullptr;
+ delete foo;
+
+ auto bar = new long;
+ assert_ptr_not_null(bar, "Unexpected new failure");
+ delete bar;
+ // Test nullptr handling.
+ bar = nullptr;
+ delete bar;
}
TEST_END