From 1df1efa3921841fb5fc7fc15e8112eed4375de9f Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 7 Sep 2016 09:55:37 -0700 Subject: Fixup CPDFSDK_PageView and CPDF_Page interactions. There are several issues when CPDFSDK_PageView and CPDF_Page interact, especially around deletion. This Cl fixes up several places where things go wrong working with these objects. BUG=chromium:632709 Review-Url: https://codereview.chromium.org/2319663002 --- fpdfsdk/fpdfview.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'fpdfsdk/fpdfview.cpp') diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index dee71ac9e2..1c0af1dc10 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -673,9 +673,20 @@ DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { #else // PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = static_cast(pPage->GetView()); - if (pPageView && pPageView->IsLocked()) { - pPageView->TakeOverPage(); - return; + if (pPageView) { + if (pPageView->IsLocked()) { + pPageView->TakePageOwnership(); + return; + } + + bool owned = pPageView->OwnsPage(); + // This will delete the |pPageView| object. We must cleanup the PageView + // first because it will attempt to reset the View on the |pPage| during + // destruction. + pPageView->GetSDKDocument()->RemovePageView(pPage); + // If the page was owned then the pageview will have deleted the page. + if (owned) + return; } delete pPage; #endif // PDF_ENABLE_XFA -- cgit v1.2.3