Commit 5c04f9ac authored by Louis Brandy's avatar Louis Brandy Committed by Facebook Github Bot

ReadMostlySharedPtrTest, subtle test bug caught by -fsanitize-address-use-after-scope

Summary: Because these `atomic<int>` are referenced in the destructor of the `ReadMostlyMainPtr`, they must be declared before it, otherwise they are destroyed before it i.

Reviewed By: yfeldblum

Differential Revision: D4854964

fbshipit-source-id: 625a8f890bba166b682ca13558f8bcde86edcc75
parent 6ea7629b
...@@ -211,10 +211,12 @@ TEST_F(ReadMostlySharedPtrTest, Ctor) { ...@@ -211,10 +211,12 @@ TEST_F(ReadMostlySharedPtrTest, Ctor) {
} }
TEST_F(ReadMostlySharedPtrTest, ClearingCache) { TEST_F(ReadMostlySharedPtrTest, ClearingCache) {
std::atomic<int> cnt1{0};
std::atomic<int> cnt2{0};
ReadMostlyMainPtr<TestObject> ptr; ReadMostlyMainPtr<TestObject> ptr;
// Store 1. // Store 1.
std::atomic<int> cnt1{0};
ptr.reset(folly::make_unique<TestObject>(1, cnt1)); ptr.reset(folly::make_unique<TestObject>(1, cnt1));
Coordinator c; Coordinator c;
...@@ -230,7 +232,6 @@ TEST_F(ReadMostlySharedPtrTest, ClearingCache) { ...@@ -230,7 +232,6 @@ TEST_F(ReadMostlySharedPtrTest, ClearingCache) {
EXPECT_EQ(1, cnt1.load()); EXPECT_EQ(1, cnt1.load());
// Store 2 and check that 1 is destroyed. // Store 2 and check that 1 is destroyed.
std::atomic<int> cnt2{0};
ptr.reset(folly::make_unique<TestObject>(2, cnt2)); ptr.reset(folly::make_unique<TestObject>(2, cnt2));
EXPECT_EQ(0, cnt1.load()); EXPECT_EQ(0, cnt1.load());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment