Merge pull request #65051 from ClickHouse/fix_capture_this_in_context_access

Capture weak_ptr of ContextAccess for safety
This commit is contained in:
Alexander Gololobov 2024-06-13 13:37:36 +00:00 committed by GitHub
commit cb84733143
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -360,10 +360,13 @@ void ContextAccess::setUser(const UserPtr & user_) const
subscription_for_roles_changes.reset();
enabled_roles = access_control->getEnabledRoles(current_roles, current_roles_with_admin_option);
subscription_for_roles_changes = enabled_roles->subscribeForChanges([this](const std::shared_ptr<const EnabledRolesInfo> & roles_info_)
subscription_for_roles_changes = enabled_roles->subscribeForChanges([weak_ptr = weak_from_this()](const std::shared_ptr<const EnabledRolesInfo> & roles_info_)
{
std::lock_guard lock{mutex};
setRolesInfo(roles_info_);
auto ptr = weak_ptr.lock();
if (!ptr)
return;
std::lock_guard lock{ptr->mutex};
ptr->setRolesInfo(roles_info_);
});
setRolesInfo(enabled_roles->getRolesInfo());