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/fpdf_dataavail.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/fpdf_dataavail.cpp')
-rw-r--r-- | fpdfsdk/fpdf_dataavail.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp index f2358d2e5c..2511441af5 100644 --- a/fpdfsdk/fpdf_dataavail.cpp +++ b/fpdfsdk/fpdf_dataavail.cpp @@ -118,16 +118,17 @@ CFPDF_DataAvail* CFPDFDataAvailFromFPDFAvail(FPDF_AVAIL avail) { DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, FPDF_FILEACCESS* file) { - CFPDF_DataAvail* pAvail = new CFPDF_DataAvail; + auto pAvail = pdfium::MakeUnique<CFPDF_DataAvail>(); pAvail->m_FileAvail->Set(file_avail); pAvail->m_FileRead->Set(file); pAvail->m_pDataAvail = pdfium::MakeUnique<CPDF_DataAvail>( pAvail->m_FileAvail.get(), pAvail->m_FileRead, true); - return pAvail; + return pAvail.release(); // Caller takes ownership. } DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail) { - delete (CFPDF_DataAvail*)avail; + // Take ownership back from caller and destroy. + std::unique_ptr<CFPDF_DataAvail>(static_cast<CFPDF_DataAvail*>(avail)); } DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, |