Skip to content

Commit 0a3a4fd

Browse files
authored
Merge pull request #3865 from apple/lldb-Unlock-Swift-scratch-context-before-early-return
[lldb] Unlock Swift scratch context before early return
2 parents f42dcac + 2911abe commit 0a3a4fd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lldb/source/Target/Target.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,9 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
22862286
// thread) is holding a read lock to the scratch context and
22872287
// replacing it could cause a use-after-free later on.
22882288
if (GetSwiftScratchContextLock().try_lock()) {
2289+
auto unlock = llvm::make_scope_exit([this] {
2290+
GetSwiftScratchContextLock().unlock();
2291+
});
22892292
if (m_use_scratch_typesystem_per_module)
22902293
DisplayFallbackSwiftContextErrors(swift_ast_ctx);
22912294
else if (StreamSP errs = GetDebugger().GetAsyncErrorStream()) {
@@ -2335,7 +2338,6 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
23352338
llvm::make_error<llvm::StringError>("DIAF", llvm::inconvertibleErrorCode());
23362339
}
23372340
}
2338-
GetSwiftScratchContextLock().unlock();
23392341
}
23402342
}
23412343
} else if (create_on_demand) {

0 commit comments

Comments
 (0)