Use fxcrt::AutoNuller<T> in CPDFXA_Context::LoadXFADoc().

Change-Id: I89f0bcfb8386008c0f5b1c91813e58916680f802
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72833
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index a431e38..cbd3624 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -13,6 +13,7 @@
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/cpdf_document.h"
 #include "core/fpdfapi/parser/cpdf_seekablemultistream.h"
+#include "core/fxcrt/autonuller.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/xml/cfx_xmldocument.h"
 #include "core/fxcrt/xml/cfx_xmlparser.h"
@@ -130,6 +131,7 @@
     return false;
   }
 
+  AutoNuller<std::unique_ptr<CXFA_FFDoc>> doc_nuller(&m_pXFADoc);
   m_pXFADoc =
       CXFA_FFDoc::CreateAndOpen(m_pXFAApp.get(), m_pDocEnv.get(),
                                 m_pPDFDoc.Get(), m_pGCHeap.get(), m_pXML.get());
@@ -139,7 +141,6 @@
   }
 
   if (!m_pXFAApp->LoadFWLTheme(m_pXFADoc.get())) {
-    m_pXFADoc.reset();
     FXSYS_SetLastError(FPDF_ERR_XFALAYOUT);
     return false;
   }
@@ -150,16 +151,19 @@
   else
     m_FormType = FormType::kXFAForeground;
 
+  AutoNuller<UnownedPtr<CXFA_FFDocView>> view_nuller(&m_pXFADocView);
   m_pXFADocView = m_pXFADoc->CreateDocView();
+
   if (m_pXFADocView->StartLayout() < 0) {
-    m_pXFADocView = nullptr;
-    m_pXFADoc.reset();
     FXSYS_SetLastError(FPDF_ERR_XFALAYOUT);
     return false;
   }
 
   m_pXFADocView->DoLayout();
   m_pXFADocView->StopLayout();
+
+  view_nuller.AbandonNullification();
+  doc_nuller.AbandonNullification();
   m_nLoadStatus = FXFA_LOADSTATUS_LOADED;
   return true;
 }