From d5702be495c7af19ffec6449472eb19d2acb8b8c Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Thu, 20 May 2021 10:07:53 +1000 Subject: [PATCH] Core - ClientAdapter::OnProcessMessageReceived add nullptr checks Follow up to https://github.com/cefsharp/CefSharp/discussions/3573 --- .../Internals/ClientAdapter.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp b/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp index dde7aaf1d..d71a3b415 100644 --- a/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp +++ b/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp @@ -1141,6 +1141,11 @@ namespace CefSharp auto objectRepository = browserAdapter->JavascriptObjectRepository; + if (objectRepository == nullptr) + { + return true; + } + auto callbackId = GetInt64(argList, 0); auto objectNames = argList->GetList(1); @@ -1173,6 +1178,11 @@ namespace CefSharp auto objectRepository = browserAdapter->JavascriptObjectRepository; + if (objectRepository == nullptr) + { + return true; + } + auto boundObjects = argList->GetList(0); auto objs = gcnew List^>(boundObjects->GetSize()); for (size_t i = 0; i < boundObjects->GetSize(); i++) @@ -1346,6 +1356,15 @@ namespace CefSharp } auto callbackFactory = browserAdapter->JavascriptCallbackFactory; + auto methodRunnerQueue = browserAdapter->MethodRunnerQueue; + + //Dispose is called on a different thread, so there's a chance + //dispose is called after our IsDisposed checks, make sure we have + //actual references. + if (callbackFactory == nullptr || methodRunnerQueue == nullptr) + { + return true; + } auto frameId = frame->GetIdentifier(); auto objectId = GetInt64(argList, 0); @@ -1358,7 +1377,7 @@ namespace CefSharp methodInvocation->Parameters->Add(DeserializeObject(arguments, i, callbackFactory)); } - browserAdapter->MethodRunnerQueue->Enqueue(methodInvocation); + methodRunnerQueue->Enqueue(methodInvocation); handled = true; }