@@ -2286,6 +2286,9 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
2286
2286
// thread) is holding a read lock to the scratch context and
2287
2287
// replacing it could cause a use-after-free later on.
2288
2288
if (GetSwiftScratchContextLock ().try_lock ()) {
2289
+ auto unlock = llvm::make_scope_exit ([this ] {
2290
+ GetSwiftScratchContextLock ().unlock ();
2291
+ });
2289
2292
if (m_use_scratch_typesystem_per_module)
2290
2293
DisplayFallbackSwiftContextErrors (swift_ast_ctx);
2291
2294
else if (StreamSP errs = GetDebugger ().GetAsyncErrorStream ()) {
@@ -2309,10 +2312,8 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
2309
2312
m_scratch_type_system_map.RemoveTypeSystemsForLanguage (language);
2310
2313
type_system_or_err = m_scratch_type_system_map.GetTypeSystemForLanguage (
2311
2314
language, this , create_on_demand, compiler_options);
2312
- if (!type_system_or_err) {
2313
- GetSwiftScratchContextLock ().unlock ();
2315
+ if (!type_system_or_err)
2314
2316
return type_system_or_err.takeError ();
2315
- }
2316
2317
2317
2318
if (auto *new_swift_ast_ctx =
2318
2319
llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(
@@ -2337,7 +2338,6 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
2337
2338
llvm::make_error<llvm::StringError>(" DIAF" , llvm::inconvertibleErrorCode ());
2338
2339
}
2339
2340
}
2340
- GetSwiftScratchContextLock ().unlock ();
2341
2341
}
2342
2342
}
2343
2343
} else if (create_on_demand) {
0 commit comments