diff --git a/passphrase_cache.cc b/passphrase_cache.cc index d11a2f1..c7dad6f 100644 --- a/passphrase_cache.cc +++ b/passphrase_cache.cc @@ -55,19 +55,24 @@ namespace pEp { bool PassphraseCache::for_each_passphrase(const passphrase_callee& callee) { - std::lock_guard lock(_mtx); - cleanup(); - if (callee("")) return true; - if (!_stored.empty() && callee(_stored)) - return true; - - for (auto entry=_cache.begin(); entry!=_cache.end(); ++entry) { - if (callee(entry->passphrase)) { - refresh(entry); + { + std::lock_guard lock(_shared_mtx); + if (!_stored.empty() && callee(_stored)) return true; + } + + { + std::lock_guard lock(_mtx); + cleanup(); + + for (auto entry=_cache.begin(); entry!=_cache.end(); ++entry) { + if (callee(entry->passphrase)) { + refresh(entry); + return true; + } } }