1
0
Mirror von https://github.com/tkuschel/bees.git synchronisiert 2026-05-08 04:59:37 +02:00

crucible: cache: construct return value before releasing lock

If we release the lock first (and C++ destructor order says we do), then
the return value will be constructed from data living in an unprotected
container object.  That data might be destroyed before we get to the
copy constructor for the return value.

Make a temporary copy of the return value that won't be destroyed by any
other thread, then unlock the mutex, then return the copy object.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
Dieser Commit ist enthalten in:
Zygo Blaxell
2017-01-22 12:07:10 -05:00
Ursprung 123d4e83c5
Commit c58e5cd75b
+3 -1
Datei anzeigen
@@ -154,7 +154,9 @@ namespace crucible {
if (!inserted) {
found->second.first = m_ctr++;
}
return found->second.second;
// Make copy before releasing lock
auto rv = found->second.second;
return rv;
}
template<class Return, class... Arguments>