From: Andrii Grynenko Date: Thu, 2 Oct 2014 03:34:27 +0000 (-0700) Subject: Leak folly::SingletonVault X-Git-Tag: v0.22.0~299 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f0c0e8d28099e9d88b9f23d72f2df213f349eb5e;p=folly.git Leak folly::SingletonVault Summary: This will ensure SingletonVault is always available. It matters for singletons, not managed by folly::Singleton. Singletons in it will actually be destroyed via static SingletonVaultDestructor. This does the same as D1591270 (which got reverted), but doesn't change destruction order. Test Plan: Run tests which were broken by D1591270 Reviewed By: chip@fb.com Subscribers: njormrod FB internal diff: D1594898 --- diff --git a/folly/experimental/Singleton.cpp b/folly/experimental/Singleton.cpp index 7934ab1a..4cfacd5a 100644 --- a/folly/experimental/Singleton.cpp +++ b/folly/experimental/Singleton.cpp @@ -55,7 +55,17 @@ void SingletonVault::destroyInstances() { } SingletonVault* SingletonVault::singleton() { - static SingletonVault vault; - return &vault; + static SingletonVault* vault = new SingletonVault(); + + class SingletonVaultDestructor { + public: + ~SingletonVaultDestructor() { + SingletonVault::singleton()->destroyInstances(); + } + }; + static SingletonVaultDestructor singletonVaultDestructor; + + return vault; } + } diff --git a/folly/experimental/Singleton.h b/folly/experimental/Singleton.h index 524e5217..ed912abe 100644 --- a/folly/experimental/Singleton.h +++ b/folly/experimental/Singleton.h @@ -167,6 +167,8 @@ class SingletonVault { enum class Type { Strict, Relaxed }; explicit SingletonVault(Type type = Type::Relaxed) : type_(type) {} + + // Destructor is only called by unit tests to check destroyInstances. ~SingletonVault(); typedef std::function TeardownFunc;