summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfformfill.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-05-16 15:33:20 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-16 23:26:47 +0000
commitfe91c6c8211cec39f871d9202556e1957bf81983 (patch)
treeb7e763f7affe4c71de67393fbd320c1fed477e0f /fpdfsdk/fpdfformfill.cpp
parent365333552cf67b7c97c4093177e7ed7b43f540ab (diff)
downloadpdfium-fe91c6c8211cec39f871d9202556e1957bf81983.tar.xz
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 <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfformfill.cpp')
-rw-r--r--fpdfsdk/fpdfformfill.cpp20
1 files changed, 11 insertions, 9 deletions
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<CPDFSDK_FormFillEnvironment>(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<CPDFXFA_Context*>(document);
+ auto* pContext = static_cast<CPDFXFA_Context*>(document);
if (pContext->GetDocType() != XFA_DocType::Dynamic &&
pContext->GetDocType() != XFA_DocType::Static)
return;
- std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>;
CFX_PointF ptPopup;
ptPopup.x = x;
ptPopup.y = y;
- static_cast<CXFA_FFWidget*>(hWidget)
- ->GetSuggestWords(ptPopup, *sSuggestWords);
- *stringHandle = ToFPDFStringHandle(sSuggestWords);
+ auto sSuggestWords = pdfium::MakeUnique<std::vector<CFX_ByteString>>();
+ static_cast<CXFA_FFWidget*>(hWidget)->GetSuggestWords(ptPopup,
+ sSuggestWords.get());
+
+ // Caller takes ownership.
+ *stringHandle = ToFPDFStringHandle(sSuggestWords.release());
}
DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {