@@ -2296,6 +2296,9 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
2296
2296
// thread) is holding a read lock to the scratch context and
2297
2297
// replacing it could cause a use-after-free later on.
2298
2298
if (GetSwiftScratchContextLock ().try_lock ()) {
2299
+ auto unlock = llvm::make_scope_exit ([this ] {
2300
+ GetSwiftScratchContextLock ().unlock ();
2301
+ });
2299
2302
if (m_use_scratch_typesystem_per_module)
2300
2303
DisplayFallbackSwiftContextErrors (swift_ast_ctx);
2301
2304
else if (StreamSP errs = GetDebugger ().GetAsyncErrorStream ()) {
@@ -2319,10 +2322,8 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
2319
2322
m_scratch_type_system_map.RemoveTypeSystemsForLanguage (language);
2320
2323
type_system_or_err = m_scratch_type_system_map.GetTypeSystemForLanguage (
2321
2324
language, this , create_on_demand, compiler_options);
2322
- if (!type_system_or_err) {
2323
- GetSwiftScratchContextLock ().unlock ();
2325
+ if (!type_system_or_err)
2324
2326
return type_system_or_err.takeError ();
2325
- }
2326
2327
2327
2328
if (auto *new_swift_ast_ctx =
2328
2329
llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(
@@ -2347,7 +2348,6 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
2347
2348
llvm::make_error<llvm::StringError>(" DIAF" , llvm::inconvertibleErrorCode ());
2348
2349
}
2349
2350
}
2350
- GetSwiftScratchContextLock ().unlock ();
2351
2351
}
2352
2352
}
2353
2353
} else if (create_on_demand) {
0 commit comments