Properly ref-count CPDFXFA_Page


Change-Id: Ibd1ebe4191f61e20d815de7f1a1094d78b72e6a7
Reviewed-on: https://pdfium-review.googlesource.com/5391
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index 739723f..66ff028 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -118,15 +118,15 @@
   pPageDict->SetNewFor<CPDF_Dictionary>("Resources");
 
 #ifdef PDF_ENABLE_XFA
-  CPDFXFA_Page* pPage =
-      new CPDFXFA_Page(static_cast<CPDFXFA_Context*>(document), page_index);
-  pPage->LoadPDFPage(pPageDict);
+  auto pXFAPage = pdfium::MakeRetain<CPDFXFA_Page>(
+      static_cast<CPDFXFA_Context*>(document), page_index);
+  pXFAPage->LoadPDFPage(pPageDict);
+  return pXFAPage.Leak();
 #else   // PDF_ENABLE_XFA
   CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
   pPage->ParseContent();
-#endif  // PDF_ENABLE_XFA
-
   return pPage;
+#endif  // PDF_ENABLE_XFA
 }
 
 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {