From 6ea7629b0091ebd0284106cdbfee36b80619b62f Mon Sep 17 00:00:00 2001 From: Louis Brandy Date: Fri, 7 Apr 2017 19:25:07 -0700 Subject: [PATCH] fix EvictingCacheMap test bug found w/ -fsanitize-address-use-after-scope Summary: This test actually stores references to `sum` in objects it puts into the `EvictingCacheMap`. Those references get accessed in the destructor of the objects, which is the destructor of the `EvictingCacheMap`. That means the `sum` variable must outlive (and be declared -before-) the `EvictingCacheMap` it's testing. Reviewed By: yfeldblum, meyering Differential Revision: D4854619 fbshipit-source-id: b0a3109278f48d10b4cd0c52a12cb2064f4a00c5 --- folly/test/EvictingCacheMapTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/folly/test/EvictingCacheMapTest.cpp b/folly/test/EvictingCacheMapTest.cpp index cac07641..85a4a5ed 100644 --- a/folly/test/EvictingCacheMapTest.cpp +++ b/folly/test/EvictingCacheMapTest.cpp @@ -317,15 +317,15 @@ TEST(EvictingCacheMap, DestructorInvocationTest) { int* ref; }; + int sum; EvictingCacheMap map(0); + EXPECT_EQ(0, map.size()); EXPECT_TRUE(map.empty()); for (int i = 0; i < 100; i++) { EXPECT_FALSE(map.exists(i)); } - int sum; - for (int i = 0; i < 100; i++) { map.set(i, SumInt(i, &sum)); EXPECT_EQ(i + 1, map.size()); -- 2.34.1