summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-08-17 16:18:43 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-08-23 11:35:19 +0000
commit7bc32104660dd9b5dfa9920a288797a7c2790559 (patch)
tree832fe410db0ec6eef8c0fb8263124a09325190e2
parentcf7d82a79dff4ea5c53e0908ed5c13ce1f87796d (diff)
Ensure WebEngineContext::destroy() is called before the destructor
Add a false reference only removed after destroy() is called, so the tearing down of static objects won't dereference it before the QApplication is destroyed and the post routines including destroy() are called. Also adds a little safety by asserting destroy() has been called before ~WebEngineContext() and make sure we don't create a new WebEngineContext() during shut down. Task-number: QTBUG-54769 Change-Id: I2b1d189f9ebd8da2dc9f322f9bb307a5aa0c6a2f Reviewed-by: Florian Bruhin <qt-project.org@the-compiler.org> Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
-rw-r--r--src/core/web_engine_context.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index 98fba0897..7d1e5d609 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -102,6 +102,7 @@ QT_END_NAMESPACE
namespace {
scoped_refptr<QtWebEngineCore::WebEngineContext> sContext;
+static bool s_destroyed = false;
void destroyContext()
{
@@ -110,6 +111,7 @@ void destroyContext()
// WebEngineContext's pointer is used.
sContext->destroy();
sContext = 0;
+ s_destroyed = true;
}
bool usingANGLE()
@@ -184,18 +186,29 @@ void WebEngineContext::destroy()
// RenderProcessHostImpl should be destroyed before WebEngineContext since
// default BrowserContext might be used by the RenderprocessHostImpl's destructor.
m_browserRunner.reset(0);
+
+ // Drop the false reference.
+ sContext->Release();
}
WebEngineContext::~WebEngineContext()
{
+ // WebEngineContext::destroy() must be called before we are deleted
+ Q_ASSERT(!m_globalQObject);
+ Q_ASSERT(!m_devtools);
+ Q_ASSERT(!m_browserRunner);
}
scoped_refptr<WebEngineContext> WebEngineContext::current()
{
+ if (s_destroyed)
+ return nullptr;
if (!sContext.get()) {
sContext = new WebEngineContext();
// Make sure that we ramp down Chromium before QApplication destroys its X connection, etc.
qAddPostRoutine(destroyContext);
+ // Add a false reference so there is no race between unreferencing sContext and a global QApplication.
+ sContext->AddRef();
}
return sContext;
}