win: alloy: Fix potential crash if browser creation is aborted (fixes #3862)

This commit is contained in:
Marshall Greenblatt 2025-03-21 14:21:42 -04:00
parent 49ac6882ec
commit 0bf995ae26

View File

@ -173,10 +173,11 @@ bool CefBrowserPlatformDelegateNativeWin::CreateHostWindow() {
window_info_.parent_window, window_info_.menu, window_info_.parent_window, window_info_.menu,
::GetModuleHandle(nullptr), this); ::GetModuleHandle(nullptr), this);
// It's possible for CreateWindowEx to fail if the parent window was // It's possible for CreateWindowEx to fail if the parent window was destroyed
// destroyed between the call to CreateBrowser and the above one. // between the call to CreateBrowser and the above one. It's also possible
DCHECK(window_info_.window); // that |browser_| will be nullptr if BrowserDestroyed() was called during
if (!window_info_.window) { // this time.
if (!window_info_.window || !browser_) {
return false; return false;
} }
@ -569,10 +570,14 @@ LRESULT CALLBACK CefBrowserPlatformDelegateNativeWin::WndProc(HWND hwnd,
// Clear the user data pointer. // Clear the user data pointer.
gfx::SetWindowUserData(hwnd, nullptr); gfx::SetWindowUserData(hwnd, nullptr);
// Force the browser to be destroyed. This will result in a call to // |browser| may be nullptr if the window was destroyed during browser
// BrowserDestroyed() that will release the reference added in // creation (e.g. CreateHostWindow() returned false).
// CreateHostWindow(). if (browser) {
AlloyBrowserHostImpl::FromBaseChecked(browser)->WindowDestroyed(); // Force the browser to be destroyed. This will result in a call to
// BrowserDestroyed() that will release the reference added in
// CreateHostWindow().
AlloyBrowserHostImpl::FromBaseChecked(browser)->WindowDestroyed();
}
} }
break; break;