From c41ccce3d887157fa3ead41a352cd794cbcc22b7 Mon Sep 17 00:00:00 2001 From: roytam1 Date: Tue, 14 Dec 2021 22:42:42 +0800 Subject: [PATCH] Bug 1730120, close ContentViewer properly if initialization fails, r=nika a=RyanVM --- platform/docshell/base/nsDocShell.cpp | 4 ++++ platform/layout/base/nsDocumentViewer.cpp | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/docshell/base/nsDocShell.cpp b/platform/docshell/base/nsDocShell.cpp index c40fbd7a1..5b89df511 100644 --- a/platform/docshell/base/nsDocShell.cpp +++ b/platform/docshell/base/nsDocShell.cpp @@ -9353,7 +9353,11 @@ nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) mContentViewer->SetNavigationTiming(mTiming); if (NS_FAILED(mContentViewer->Init(widget, bounds))) { + nsCOMPtr viewer = mContentViewer; + viewer->Close(nullptr); + viewer->Destroy(); mContentViewer = nullptr; + mCurrentURI = nullptr; NS_WARNING("ContentViewer Initialization failed"); return NS_ERROR_FAILURE; } diff --git a/platform/layout/base/nsDocumentViewer.cpp b/platform/layout/base/nsDocumentViewer.cpp index a0af38c28..ce8ab1c3d 100644 --- a/platform/layout/base/nsDocumentViewer.cpp +++ b/platform/layout/base/nsDocumentViewer.cpp @@ -1602,8 +1602,6 @@ DetachContainerRecurse(nsIDocShell *aShell) NS_IMETHODIMP nsDocumentViewer::Destroy() { - NS_ASSERTION(mDocument, "No document in Destroy()!"); - #ifdef NS_PRINTING // Here is where we check to see if the document was still being prepared // for printing when it was asked to be destroy from someone externally