From efaf7a6b856d741fb2160adb46be16662c6183d2 Mon Sep 17 00:00:00 2001 From: Matt Crocker Date: Sun, 19 Nov 2017 14:08:11 -0800 Subject: [PATCH] Avoid race condition where login handler webcontents becomes null --- atom/browser/api/atom_api_app.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index d878926580a5..1534f648498f 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -633,12 +633,17 @@ void App::OnLogin(LoginHandler* login_handler, const base::DictionaryValue& request_details) { v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); - bool prevent_default = Emit( - "login", - WebContents::CreateFrom(isolate(), login_handler->GetWebContents()), - request_details, - login_handler->auth_info(), - base::Bind(&PassLoginInformation, make_scoped_refptr(login_handler))); + bool prevent_default = false; + content::WebContents* web_contents = login_handler->GetWebContents(); + if (web_contents) { + prevent_default = + Emit("login", + WebContents::CreateFrom(isolate(), web_contents), + request_details, + login_handler->auth_info(), + base::Bind(&PassLoginInformation, + make_scoped_refptr(login_handler))); + } // Default behavior is to always cancel the auth. if (!prevent_default)