Use std::unique_ptr inside FPDFDOC_ExitFormFillEnvironment()
Replace an explicit delete on |pFormFillEnv| with std::unique_ptr.
Change-Id: I4d311270b6d65c1f90709f73ea8124c21909e8f7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/64690
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index 90ac589..cc3d5d5 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -330,11 +330,14 @@
FPDF_EXPORT void FPDF_CALLCONV
FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv =
- CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle);
- if (!pFormFillEnv)
+ if (!hHandle)
return;
+ // Take back ownership of the form fill environment. This is the inverse of
+ // FPDFDOC_InitFormFillEnvironment() above.
+ std::unique_ptr<CPDFSDK_FormFillEnvironment> pFormFillEnv(
+ CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle));
+
#ifdef PDF_ENABLE_XFA
// Reset the focused annotations and remove the SDK document from the
// XFA document.
@@ -346,7 +349,6 @@
if (pContext)
pContext->SetFormFillEnv(nullptr);
#endif // PDF_ENABLE_XFA
- delete pFormFillEnv;
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
diff --git a/public/fpdf_formfill.h b/public/fpdf_formfill.h
index c540721..9979a4a 100644
--- a/public/fpdf_formfill.h
+++ b/public/fpdf_formfill.h
@@ -1081,12 +1081,14 @@
/*
* Function: FPDFDOC_ExitFormFillEnvironment
- * Exit form fill environment.
+ * Take ownership of |hHandle| and exit form fill environment.
* Parameters:
* hHandle - Handle to the form fill module, as returned by
* FPDFDOC_InitFormFillEnvironment().
* Return Value:
* None.
+ * Comments:
+ * This function is a no-op when |hHandle| is null.
*/
FPDF_EXPORT void FPDF_CALLCONV
FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle);