diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-05-16 15:33:20 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-16 23:26:47 +0000 |
commit | fe91c6c8211cec39f871d9202556e1957bf81983 (patch) | |
tree | b7e763f7affe4c71de67393fbd320c1fed477e0f /fpdfsdk/fpdfeditpage.cpp | |
parent | 365333552cf67b7c97c4093177e7ed7b43f540ab (diff) | |
download | pdfium-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/fpdfeditpage.cpp')
-rw-r--r-- | fpdfsdk/fpdfeditpage.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 66ff028141..df752d4029 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -63,14 +63,13 @@ bool IsPageObject(CPDF_Page* pPage) { } // namespace DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { - CPDF_Document* pDoc = new CPDF_Document(nullptr); + auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr); pDoc->CreateNewDoc(); - time_t currentTime; + time_t currentTime; CFX_ByteString DateStr; - if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { - if (-1 != time(¤tTime)) { + if (time(¤tTime) != -1) { tm* pTM = localtime(¤tTime); if (pTM) { DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, @@ -80,15 +79,15 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { } } - CPDF_Dictionary* pInfoDict = nullptr; - pInfoDict = pDoc->GetInfo(); + CPDF_Dictionary* pInfoDict = pDoc->GetInfo(); if (pInfoDict) { if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false); pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium"); } - return FPDFDocumentFromCPDFDocument(pDoc); + // Caller takes ownership of pDoc. + return FPDFDocumentFromCPDFDocument(pDoc.release()); } DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { @@ -121,19 +120,17 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, auto pXFAPage = pdfium::MakeRetain<CPDFXFA_Page>( static_cast<CPDFXFA_Context*>(document), page_index); pXFAPage->LoadPDFPage(pPageDict); - return pXFAPage.Leak(); + return pXFAPage.Leak(); // Caller takes ownership. #else // PDF_ENABLE_XFA - CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true); + auto pPage = pdfium::MakeUnique<CPDF_Page>(pDoc, pPageDict, true); pPage->ParseContent(); - return pPage; + return pPage.release(); // Caller takes ownership. #endif // PDF_ENABLE_XFA } DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!IsPageObject(pPage)) - return -1; - return pPage->GetPageRotation(); + return IsPageObject(pPage) ? pPage->GetPageRotation() : -1; } DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |