From fe91c6c8211cec39f871d9202556e1957bf81983 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 16 May 2017 15:33:20 -0700 Subject: Be skeptical of bare |new|s. In particular, prefer an explicit .release() call when handing ownership of an object to a caller across a C-API. Change-Id: Ic3784e9d0b2d378a08d388989eaea7c9166bacd1 Reviewed-on: https://pdfium-review.googlesource.com/5470 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fpdfsdk/fpdfformfill.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'fpdfsdk/fpdfformfill.cpp') diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index de200cf7bb..a466e73abb 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -263,14 +263,14 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, return pDocument->GetFormFillEnv(); #endif - CPDFSDK_FormFillEnvironment* pFormFillEnv = - new CPDFSDK_FormFillEnvironment(pDocument, formInfo); + auto pFormFillEnv = + pdfium::MakeUnique(pDocument, formInfo); #ifdef PDF_ENABLE_XFA - pDocument->SetFormFillEnv(pFormFillEnv); + pDocument->SetFormFillEnv(pFormFillEnv.get()); #endif // PDF_ENABLE_XFA - return pFormFillEnv; + return pFormFillEnv.release(); // Caller takes ownership. } DLLEXPORT void STDCALL @@ -575,18 +575,20 @@ FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, if (!hWidget || !document) return; - CPDFXFA_Context* pContext = static_cast(document); + auto* pContext = static_cast(document); if (pContext->GetDocType() != XFA_DocType::Dynamic && pContext->GetDocType() != XFA_DocType::Static) return; - std::vector* sSuggestWords = new std::vector; CFX_PointF ptPopup; ptPopup.x = x; ptPopup.y = y; - static_cast(hWidget) - ->GetSuggestWords(ptPopup, *sSuggestWords); - *stringHandle = ToFPDFStringHandle(sSuggestWords); + auto sSuggestWords = pdfium::MakeUnique>(); + static_cast(hWidget)->GetSuggestWords(ptPopup, + sSuggestWords.get()); + + // Caller takes ownership. + *stringHandle = ToFPDFStringHandle(sSuggestWords.release()); } DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) { -- cgit v1.2.3