diff --git a/chrome/browser/digital_credentials/digital_identity_provider_desktop.cc b/chrome/browser/digital_credentials/digital_identity_provider_desktop.cc index 633288159d4df..0d7d1ea717922 100644 --- a/chrome/browser/digital_credentials/digital_identity_provider_desktop.cc +++ b/chrome/browser/digital_credentials/digital_identity_provider_desktop.cc @@ -399,8 +399,16 @@ void DigitalIdentityProviderDesktop::EndRequestWithError( return; } + // `dialog_.reset()` synchronously closes the dialog widget which (via + // activation observers) may destroy the hosting WebContents and therefore + // `this` - see the matching guard in + // DigitalIdentityRequestImpl::CompleteRequestWithStatus. Move everything we + // still need onto the stack so `this` is not dereferenced afterwards. + DigitalIdentityCallback callback = std::move(callback_); + bluetooth_manual_dialog_controller_.reset(); dialog_.reset(); + // `this` may be deleted at this point. - std::move(callback_).Run(base::unexpected(status)); + std::move(callback).Run(base::unexpected(status)); }