Commit 6ea7629b authored by Louis Brandy's avatar Louis Brandy Committed by Facebook Github Bot

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
parent 9620aea0
...@@ -317,15 +317,15 @@ TEST(EvictingCacheMap, DestructorInvocationTest) { ...@@ -317,15 +317,15 @@ TEST(EvictingCacheMap, DestructorInvocationTest) {
int* ref; int* ref;
}; };
int sum;
EvictingCacheMap<int, SumInt> map(0); EvictingCacheMap<int, SumInt> map(0);
EXPECT_EQ(0, map.size()); EXPECT_EQ(0, map.size());
EXPECT_TRUE(map.empty()); EXPECT_TRUE(map.empty());
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
EXPECT_FALSE(map.exists(i)); EXPECT_FALSE(map.exists(i));
} }
int sum;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
map.set(i, SumInt(i, &sum)); map.set(i, SumInt(i, &sum));
EXPECT_EQ(i + 1, map.size()); EXPECT_EQ(i + 1, map.size());
......
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