Commit 82bb8621 authored by Adrian Hamza's avatar Adrian Hamza Committed by Andre Azevedo

Add null check to avoid crash in unit tests that use mock singletons.

Summary: Some unit tests owned by my team are failing due to segmentation fault in SingletonHolder<T>::registerSingletonMock -> SingletonHolder<T>::destroyInstance.

Test Plan: Run folly unit tests and my unit tests.

Reviewed By: henryf@fb.com

Subscribers: trunkagent, folly-diffs@, yfeldblum

FB internal diff: D1873889

Signature: t1:1873889:1425925156:29d54092939d7e9debea3fd55f7105fd320e987e

Blame Revision: 91f4942e
parent e87194b3
...@@ -92,16 +92,18 @@ template <typename T> ...@@ -92,16 +92,18 @@ template <typename T>
void SingletonHolder<T>::destroyInstance() { void SingletonHolder<T>::destroyInstance() {
state_ = SingletonHolderState::Dead; state_ = SingletonHolderState::Dead;
instance_.reset(); instance_.reset();
auto wait_result = destroy_baton_->timed_wait( if (destroy_baton_) {
std::chrono::steady_clock::now() + kDestroyWaitTime); auto wait_result = destroy_baton_->timed_wait(
if (!wait_result) { std::chrono::steady_clock::now() + kDestroyWaitTime);
print_destructor_stack_trace_->store(true); if (!wait_result) {
LOG(ERROR) << "Singleton of type " << type_.name() << " has a " print_destructor_stack_trace_->store(true);
<< "living reference at destroyInstances time; beware! Raw " LOG(ERROR) << "Singleton of type " << type_.name() << " has a "
<< "pointer is " << instance_ptr_ << ". It is very likely " << "living reference at destroyInstances time; beware! Raw "
<< "that some other singleton is holding a shared_ptr to it. " << "pointer is " << instance_ptr_ << ". It is very likely "
<< "Make sure dependencies between these singletons are " << "that some other singleton is holding a shared_ptr to it. "
<< "properly defined."; << "Make sure dependencies between these singletons are "
<< "properly defined.";
}
} }
} }
......
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