Index: fpdfsdk/fpdfformfill.cpp |
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp |
index 6fea1af42b061aa14c1761b06003700674b22b6f..904a3c867e04897cbd48d0464c9a421d15073074 100644 |
--- a/fpdfsdk/fpdfformfill.cpp |
+++ b/fpdfsdk/fpdfformfill.cpp |
@@ -254,8 +254,7 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
CPDFSDK_Environment* pEnv = new CPDFSDK_Environment(pDocument, formInfo); |
#ifdef PDF_ENABLE_XFA |
- // Ownership of the SDKDocument is passed to the CPDFXFA_Document. |
- pDocument->SetSDKDoc(pdfium::WrapUnique(pEnv->GetSDKDocument())); |
+ pDocument->SetSDKDoc(pEnv->GetSDKDocument()); |
CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv); |
#endif // PDF_ENABLE_XFA |
@@ -271,10 +270,12 @@ FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
#ifdef PDF_ENABLE_XFA |
CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv); |
-#else // PDF_ENABLE_XFA |
+ |
+ // Reset the focused annotations and remove the SDK document from the |
+ // XFA document. |
if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { |
- pEnv->SetSDKDocument(nullptr); |
- delete pSDKDoc; |
+ pSDKDoc->ClearAllFocusedAnnots(); |
+ pSDKDoc->GetXFADocument()->SetSDKDoc(nullptr); |
} |
#endif // PDF_ENABLE_XFA |