Skip to content

[lldb] Unlock Swift scratch context before early return #4105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -2345,7 +2348,6 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
llvm::make_error<llvm::StringError>("DIAF", llvm::inconvertibleErrorCode());
}
}
GetSwiftScratchContextLock().unlock();
}
}
} else if (create_on_demand) {
Expand Down