Skip to content

Commit

Permalink
fix new/delete in sanitize-address test
Browse files Browse the repository at this point in the history
Summary:
The use of `operator new` with sized `operator delete` in `folly/memory/test/SanitizeAddressTest.cpp` requires sized `operator delete`, which is not always available.

Delegation to the correct `operator delete` is wrapped in `folly::operator_new` and `folly::operator_delete`, so switch to these.

Reviewed By: ckwalsh

Differential Revision: D62909014

fbshipit-source-id: ce223473cdfe61ccfa50ba85e15a569aa9b245ea
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Sep 18, 2024
1 parent be81e0c commit 02ebbf5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions folly/memory/test/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ cpp_unittest(
name = "sanitize_address_test",
srcs = ["SanitizeAddressTest.cpp"],
deps = [
"//folly/lang:new",
"//folly/memory:sanitize_address",
"//folly/portability:gtest",
],
Expand Down
7 changes: 3 additions & 4 deletions folly/memory/test/SanitizeAddressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#include <folly/memory/SanitizeAddress.h>

#include <new>

#include <folly/lang/New.h>
#include <folly/portability/GTest.h>

class SanitizeAddressTest : public testing::Test {};
Expand All @@ -31,7 +30,7 @@ TEST_F(SanitizeAddressTest, asan_poison) {
// malloc

auto const addr =
static_cast<opaque*>(operator new(size, std::align_val_t{page}));
static_cast<opaque*>(folly::operator_new(size, std::align_val_t{page}));

EXPECT_EQ(nullptr, folly::asan_region_is_poisoned(addr, size));
EXPECT_EQ(0, folly::asan_address_is_poisoned(addr + offs));
Expand All @@ -58,7 +57,7 @@ TEST_F(SanitizeAddressTest, asan_poison) {

// free

operator delete(addr, size, std::align_val_t{page});
folly::operator_delete(addr, size, std::align_val_t{page});
EXPECT_EQ(
folly::kIsSanitizeAddress ? addr : nullptr,
folly::asan_region_is_poisoned(addr, size));
Expand Down

0 comments on commit 02ebbf5

Please sign in to comment.