From bfa2a97ca9f5026ceb8e8c2ce23cfc3c3e8b38a1 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 24 Jul 2017 11:38:31 -0700 Subject: Observe Annot destruction in CPDFSDK_PageView::DeleteAnnot Run test XFA-Only, since that's where the issue occurs, and the textual output is different for non-xfa. Fix a few lifetime issue in pdfium_test.cc unearthed by this test (doc must outlive pages now held in formfill info). Bug: 735912 Change-Id: Icc9e6a967c32ece67d897117896c973bb16a1515 Reviewed-on: https://pdfium-review.googlesource.com/8510 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- fpdfsdk/cpdfsdk_pageview.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp index 4780d87780..06761a5806 100644 --- a/fpdfsdk/cpdfsdk_pageview.cpp +++ b/fpdfsdk/cpdfsdk_pageview.cpp @@ -175,17 +175,23 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) { bool CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { if (!pAnnot) return false; + CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); if (!pPage || (pPage->GetContext()->GetDocType() != XFA_DocType::Static && pPage->GetContext()->GetDocType() != XFA_DocType::Dynamic)) { return false; } + CPDFSDK_Annot::ObservedPtr pObserved(pAnnot); if (GetFocusAnnot() == pAnnot) - m_pFormFillEnv->KillFocusAnnot(0); - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pFormFillEnv->GetAnnotHandlerMgr(); - if (pAnnotHandler) - pAnnotHandler->ReleaseAnnot(pAnnot); + m_pFormFillEnv->KillFocusAnnot(0); // May invoke JS, invalidating pAnnot. + + if (pObserved) { + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = + m_pFormFillEnv->GetAnnotHandlerMgr(); + if (pAnnotHandler) + pAnnotHandler->ReleaseAnnot(pObserved.Get()); + } auto it = std::find(m_SDKAnnotArray.begin(), m_SDKAnnotArray.end(), pAnnot); if (it != m_SDKAnnotArray.end()) -- cgit v1.2.3