From 7d6c9224ee85e01e33c30f6b4c6164f90bfdb952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Tue, 6 Feb 2018 14:57:15 +0100 Subject: Fix AssertBrowserContextWasntDestroyed DCHECK Triggered sometimes in tst_qwebenginedownloads if the memory allocator reuses memory for a BrowserContextQt. Change-Id: Idb2db94cf0a8419dc45c25620708f3f3da8f9ec8 Reviewed-by: Allan Sandfeld Jensen --- src/core/browser_context_adapter.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index a86c66cc5..7e9a4e41d 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -85,6 +85,13 @@ BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord) , m_httpCacheMaxSize(0) { WebEngineContext::current(); // Ensure the WebEngineContext has been initialized + + // Mark the context as live. This prevents the use-after-free DCHECK in + // AssertBrowserContextWasntDestroyed from being triggered when a new + // BrowserContextQt object is allocated at the same address as a previously + // destroyed one. Needs to be called after WebEngineContext initialization. + BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(m_browserContext.data()); + content::BrowserContext::Initialize(m_browserContext.data(), toFilePath(dataPath())); } @@ -98,6 +105,13 @@ BrowserContextAdapter::BrowserContextAdapter(const QString &storageName) , m_httpCacheMaxSize(0) { WebEngineContext::current(); // Ensure the WebEngineContext has been initialized + + // Mark the context as live. This prevents the use-after-free DCHECK in + // AssertBrowserContextWasntDestroyed from being triggered when a new + // BrowserContextQt object is allocated at the same address as a previously + // destroyed one. Needs to be called after WebEngineContext initialization. + BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(m_browserContext.data()); + content::BrowserContext::Initialize(m_browserContext.data(), toFilePath(dataPath())); } -- cgit v1.2.3