From 5c04f9ac4b09ea5d85c9690b8c36bfdab28892a8 Mon Sep 17 00:00:00 2001 From: Louis Brandy Date: Fri, 7 Apr 2017 19:38:33 -0700 Subject: [PATCH] ReadMostlySharedPtrTest, subtle test bug caught by -fsanitize-address-use-after-scope Summary: Because these `atomic` 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 --- folly/experimental/test/ReadMostlySharedPtrTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/folly/experimental/test/ReadMostlySharedPtrTest.cpp b/folly/experimental/test/ReadMostlySharedPtrTest.cpp index 15f36cb8..8b3140e9 100644 --- a/folly/experimental/test/ReadMostlySharedPtrTest.cpp +++ b/folly/experimental/test/ReadMostlySharedPtrTest.cpp @@ -211,10 +211,12 @@ TEST_F(ReadMostlySharedPtrTest, Ctor) { } TEST_F(ReadMostlySharedPtrTest, ClearingCache) { + std::atomic cnt1{0}; + std::atomic cnt2{0}; + ReadMostlyMainPtr ptr; // Store 1. - std::atomic cnt1{0}; ptr.reset(folly::make_unique(1, cnt1)); Coordinator c; @@ -230,7 +232,6 @@ TEST_F(ReadMostlySharedPtrTest, ClearingCache) { EXPECT_EQ(1, cnt1.load()); // Store 2 and check that 1 is destroyed. - std::atomic cnt2{0}; ptr.reset(folly::make_unique(2, cnt2)); EXPECT_EQ(0, cnt1.load()); -- 2.34.1