diff --git a/components/password_manager/core/browser/password_autofill_manager.cc b/components/password_manager/core/browser/password_autofill_manager.cc index c0a87381c3786..80b7690cb85aa 100644 --- a/components/password_manager/core/browser/password_autofill_manager.cc +++ b/components/password_manager/core/browser/password_autofill_manager.cc @@ -289,6 +289,10 @@ void PasswordAutofillManager::DidAcceptSuggestion( const Suggestion& suggestion, const SuggestionMetadata& metadata) { using metrics_util::PasswordDropdownSelectedOption; + // On macOS, OnPasswordCredentialSuggestionAccepted() may synchronously spin + // a nested run loop (AuthorizationCopyRights) during which `this` can be + // destroyed. Guard the trailing member accesses below the switch. + auto weak_this = weak_ptr_factory_.GetWeakPtr(); switch (suggestion.type) { case autofill::SuggestionType::kGeneratePasswordEntry: password_client_->GeneratePassword(PasswordGenerationType::kAutomatic); @@ -430,6 +434,9 @@ void PasswordAutofillManager::DidAcceptSuggestion( } } + if (!weak_this) { + return; + } bool enter_loading_state = password_client_ ->GetWebAuthnCredentialsDelegateForDriver(password_manager_driver_)