summaryrefslogtreecommitdiffstats
path: root/base/lazy_instance_unittest.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-21 20:41:47 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-21 20:41:47 +0000
commitdcc6933f480397af42af5fa08d40475c13d266e8 (patch)
treeee6e4ca772e87f9ce27f60315895e7d9392d814e /base/lazy_instance_unittest.cc
parent363dc7f1f2025475b418bfee73efe3030d9b1313 (diff)
downloadchromium_src-dcc6933f480397af42af5fa08d40475c13d266e8.zip
chromium_src-dcc6933f480397af42af5fa08d40475c13d266e8.tar.gz
chromium_src-dcc6933f480397af42af5fa08d40475c13d266e8.tar.bz2
ThreadRestrictions: leak the thread local variable
LazyInstances are destroyed by the AtExitManager, but we have threads that outlive the AtExitManager that could potentially access this. Review URL: http://codereview.chromium.org/3956003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63410 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/lazy_instance_unittest.cc')
-rw-r--r--base/lazy_instance_unittest.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/base/lazy_instance_unittest.cc b/base/lazy_instance_unittest.cc
index d55f664..1731381 100644
--- a/base/lazy_instance_unittest.cc
+++ b/base/lazy_instance_unittest.cc
@@ -95,3 +95,46 @@ TEST(LazyInstanceTest, ConstructorThreadSafety) {
EXPECT_EQ(1, SlowConstructor::constructed);
}
}
+
+namespace {
+
+// DeleteLogger is an object which sets a flag when it's destroyed.
+// It accepts a bool* and sets the bool to true when the dtor runs.
+class DeleteLogger {
+ public:
+ DeleteLogger() : deleted_(NULL) {}
+ ~DeleteLogger() { *deleted_ = true; }
+
+ void SetDeletedPtr(bool* deleted) {
+ deleted_ = deleted;
+ }
+
+ private:
+ bool* deleted_;
+};
+
+} // anonymous namespace
+
+TEST(LazyInstanceTest, LeakyLazyInstance) {
+ // Check that using a plain LazyInstance causes the dtor to run
+ // when the AtExitManager finishes.
+ bool deleted1 = false;
+ {
+ base::ShadowingAtExitManager shadow;
+ static base::LazyInstance<DeleteLogger> test(base::LINKER_INITIALIZED);
+ test.Get().SetDeletedPtr(&deleted1);
+ }
+ EXPECT_TRUE(deleted1);
+
+ // Check that using a *leaky* LazyInstance makes the dtor not run
+ // when the AtExitManager finishes.
+ bool deleted2 = false;
+ {
+ base::ShadowingAtExitManager shadow;
+ static base::LazyInstance<DeleteLogger,
+ base::LeakyLazyInstanceTraits<DeleteLogger> >
+ test(base::LINKER_INITIALIZED);
+ test.Get().SetDeletedPtr(&deleted2);
+ }
+ EXPECT_FALSE(deleted2);
+}