From 19bbe660401f59272cee78089ccd107cc40412d9 Mon Sep 17 00:00:00 2001 From: Glenn Ruehle Date: Sat, 20 Jul 2013 13:29:11 -0700 Subject: [PATCH] Ignore callbacks if the browser has been deleted. --- appshell/client_app.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/appshell/client_app.cpp b/appshell/client_app.cpp index 39222c5f7..31ee0370c 100644 --- a/appshell/client_app.cpp +++ b/appshell/client_app.cpp @@ -301,12 +301,19 @@ bool ClientApp::OnProcessMessageReceived( CefRefPtr callbackFunction = callback_map_[callbackId].second; CefV8ValueList arguments; context->Enter(); - - for (size_t i = 1; i < messageArgs->GetSize(); i++) { - arguments.push_back(ListValueToV8Value(messageArgs, i)); + + // Sanity check to make sure the context is still attched to a browser. + // Async callbacks could be initiated after a browser instance has been deleted, + // which can lead to bad things. If the browser instance has been deleted, don't + // invoke this callback. + if (context->GetBrowser()) { + for (size_t i = 1; i < messageArgs->GetSize(); i++) { + arguments.push_back(ListValueToV8Value(messageArgs, i)); + } + + callbackFunction->ExecuteFunction(NULL, arguments); } - callbackFunction->ExecuteFunction(NULL, arguments); context->Exit(); callback_map_.erase(callbackId);