aboutsummaryrefslogtreecommitdiffstats
path: root/src/gmock-spec-builders.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmock-spec-builders.cc')
-rw-r--r--src/gmock-spec-builders.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/gmock-spec-builders.cc b/src/gmock-spec-builders.cc
index 06299784..6599325d 100644
--- a/src/gmock-spec-builders.cc
+++ b/src/gmock-spec-builders.cc
@@ -480,7 +480,21 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
untyped_expectation->line(), ss.str());
}
}
- untyped_expectations_.clear();
+
+ // Deleting our expectations may trigger other mock objects to be deleted, for
+ // example if an action contains a reference counted smart pointer to that
+ // mock object, and that is the last reference. So if we delete our
+ // expectations within the context of the global mutex we may deadlock when
+ // this method is called again. Instead, make a copy of the set of
+ // expectations to delete, clear our set within the mutex, and then clear the
+ // copied set outside of it.
+ UntypedExpectations expectations_to_delete;
+ untyped_expectations_.swap(expectations_to_delete);
+
+ g_gmock_mutex.Unlock();
+ expectations_to_delete.clear();
+ g_gmock_mutex.Lock();
+
return expectations_met;
}