Commit c64d359b authored by Andrii Grynenko's avatar Andrii Grynenko

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.

Test Plan: unit test

Reviewed By: chip@fb.com

Subscribers: njormrod

FB internal diff: D1591270
parent fd81069d
...@@ -55,7 +55,21 @@ void SingletonVault::destroyInstances() { ...@@ -55,7 +55,21 @@ void SingletonVault::destroyInstances() {
} }
SingletonVault* SingletonVault::singleton() { SingletonVault* SingletonVault::singleton() {
static SingletonVault vault; static SingletonVault* vault = new SingletonVault();
return &vault; return vault;
} }
namespace {
class SingletonVaultDestructor {
public:
~SingletonVaultDestructor() {
SingletonVault::singleton()->destroyInstances();
}
};
SingletonVaultDestructor singletonVaultDestructor;
}
} }
...@@ -167,6 +167,8 @@ class SingletonVault { ...@@ -167,6 +167,8 @@ class SingletonVault {
enum class Type { Strict, Relaxed }; enum class Type { Strict, Relaxed };
explicit SingletonVault(Type type = Type::Relaxed) : type_(type) {} explicit SingletonVault(Type type = Type::Relaxed) : type_(type) {}
// Destructor is only called by unit tests to check destroyInstances.
~SingletonVault(); ~SingletonVault();
typedef std::function<void(void*)> TeardownFunc; typedef std::function<void(void*)> TeardownFunc;
......
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