diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 6096764c57d7c..bf37e9efc947e 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2296,6 +2296,9 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language, // thread) is holding a read lock to the scratch context and // replacing it could cause a use-after-free later on. if (GetSwiftScratchContextLock().try_lock()) { + auto unlock = llvm::make_scope_exit([this] { + GetSwiftScratchContextLock().unlock(); + }); if (m_use_scratch_typesystem_per_module) DisplayFallbackSwiftContextErrors(swift_ast_ctx); else if (StreamSP errs = GetDebugger().GetAsyncErrorStream()) { @@ -2345,7 +2348,6 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language, llvm::make_error("DIAF", llvm::inconvertibleErrorCode()); } } - GetSwiftScratchContextLock().unlock(); } } } else if (create_on_demand) {