Skip to content

Commit b0435fd

Browse files
kastiglioneadrian-prantl
authored andcommitted
use make_scope_exit
(cherry picked from commit 2911abe)
1 parent 821a802 commit b0435fd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lldb/source/Target/Target.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,9 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
22962296
// thread) is holding a read lock to the scratch context and
22972297
// replacing it could cause a use-after-free later on.
22982298
if (GetSwiftScratchContextLock().try_lock()) {
2299+
auto unlock = llvm::make_scope_exit([this] {
2300+
GetSwiftScratchContextLock().unlock();
2301+
});
22992302
if (m_use_scratch_typesystem_per_module)
23002303
DisplayFallbackSwiftContextErrors(swift_ast_ctx);
23012304
else if (StreamSP errs = GetDebugger().GetAsyncErrorStream()) {
@@ -2319,10 +2322,8 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
23192322
m_scratch_type_system_map.RemoveTypeSystemsForLanguage(language);
23202323
type_system_or_err = m_scratch_type_system_map.GetTypeSystemForLanguage(
23212324
language, this, create_on_demand, compiler_options);
2322-
if (!type_system_or_err) {
2323-
GetSwiftScratchContextLock().unlock();
2325+
if (!type_system_or_err)
23242326
return type_system_or_err.takeError();
2325-
}
23262327

23272328
if (auto *new_swift_ast_ctx =
23282329
llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(
@@ -2347,7 +2348,6 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
23472348
llvm::make_error<llvm::StringError>("DIAF", llvm::inconvertibleErrorCode());
23482349
}
23492350
}
2350-
GetSwiftScratchContextLock().unlock();
23512351
}
23522352
}
23532353
} else if (create_on_demand) {

0 commit comments

Comments
 (0)