From 2599ff7ae76a2e7514c1794281ccb0802d6df2bc Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 8 Nov 2016 14:38:59 -0800 Subject: Fix CPDFSDK_FormFillEnvironment destruction order This was broken in 6c659ab2. Also fix m_PageMap naming while we're at it to match conventions. TEST=covered by forthcoming bug 662698 CL. Review-Url: https://codereview.chromium.org/2489663002 --- fpdfsdk/cpdfsdk_formfillenvironment.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'fpdfsdk/cpdfsdk_formfillenvironment.cpp') diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 9852bdc9b9..8ab3b46a91 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -41,12 +41,14 @@ CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment( CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() { m_bBeingDestroyed = true; - ClearAllFocusedAnnots(); - // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| - // when it cleans up. So, we must make sure it is cleaned up before - // |m_pFormFiller|. + // |m_PageMap| will try to access |m_pInterForm| when it cleans itself up. + // Make sure it is deleted before |m_pInterForm|. + m_PageMap.clear(); + + // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| when it cleans + // itself up. Make sure it is deleted before |m_pFormFiller|. m_pAnnotHandlerMgr.reset(); // Must destroy the |m_pFormFiller| before the environment (|this|) @@ -563,7 +565,7 @@ void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount, #endif // PDF_ENABLE_XFA void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() { - for (auto& it : m_pageMap) { + for (auto& it : m_PageMap) { if (it.second->IsValidSDKAnnot(GetFocusAnnot())) KillFocusAnnot(0); } @@ -572,15 +574,15 @@ void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() { CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView( UnderlyingPageType* pUnderlyingPage, bool renew) { - auto it = m_pageMap.find(pUnderlyingPage); - if (it != m_pageMap.end()) + auto it = m_PageMap.find(pUnderlyingPage); + if (it != m_PageMap.end()) return it->second.get(); if (!renew) return nullptr; CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); - m_pageMap[pUnderlyingPage].reset(pPageView); + m_PageMap[pUnderlyingPage].reset(pPageView); // Delay to load all the annotations, to avoid endless loop. pPageView->LoadFXAnnots(); return pPageView; @@ -598,8 +600,8 @@ CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) { if (!pTempPage) return nullptr; - auto it = m_pageMap.find(pTempPage); - return it != m_pageMap.end() ? it->second.get() : nullptr; + auto it = m_PageMap.find(pTempPage); + return it != m_PageMap.end() ? it->second.get() : nullptr; } void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() { @@ -647,8 +649,8 @@ bool CPDFSDK_FormFillEnvironment::ProcOpenAction() { void CPDFSDK_FormFillEnvironment::RemovePageView( UnderlyingPageType* pUnderlyingPage) { - auto it = m_pageMap.find(pUnderlyingPage); - if (it == m_pageMap.end()) + auto it = m_PageMap.find(pUnderlyingPage); + if (it == m_PageMap.end()) return; CPDFSDK_PageView* pPageView = it->second.get(); @@ -669,7 +671,7 @@ void CPDFSDK_FormFillEnvironment::RemovePageView( // Remove the page from the map to make sure we don't accidentally attempt // to use the |pPageView| while we're cleaning it up. - m_pageMap.erase(it); + m_PageMap.erase(it); } UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) { @@ -684,7 +686,7 @@ CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot) { - for (const auto& it : m_pageMap) { + for (const auto& it : m_PageMap) { CPDFSDK_PageView* pPageView = it.second.get(); if (pPageView != pSender) pPageView->UpdateView(pAnnot); -- cgit v1.2.3