summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_dataavail.cpp11
-rw-r--r--fpdfsdk/fpdfview.cpp40
2 files changed, 27 insertions, 24 deletions
diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp
index b7b47f86a1..3cc7fc0347 100644
--- a/fpdfsdk/fpdf_dataavail.cpp
+++ b/fpdfsdk/fpdf_dataavail.cpp
@@ -136,18 +136,19 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) {
if (!pDataAvail)
return nullptr;
- CPDF_Parser* pParser = new CPDF_Parser;
+ std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser);
pParser->SetPassword(password);
- CPDF_Parser::Error error =
- pParser->StartAsyncParse(pDataAvail->m_pDataAvail->GetFileRead());
+
+ std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get()));
+ CPDF_Parser::Error error = pParser->StartAsyncParse(
+ pDataAvail->m_pDataAvail->GetFileRead(), std::move(pDocument));
if (error != CPDF_Parser::SUCCESS) {
- delete pParser;
ProcessParseError(error);
return nullptr;
}
pDataAvail->m_pDataAvail->SetDocument(pParser->GetDocument());
CheckUnSupportError(pParser->GetDocument(), FPDF_ERR_SUCCESS);
- return FPDFDocumentFromCPDFDocument(pParser->GetDocument());
+ return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument());
}
DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc) {
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 8aebb550ff..29fe88d943 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -362,24 +362,25 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path,
return nullptr;
}
- CPDF_Parser* pParser = new CPDF_Parser;
+ std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser);
pParser->SetPassword(password);
- CPDF_Parser::Error error = pParser->StartParse(pFileAccess);
+ std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get()));
+ CPDF_Parser::Error error =
+ pParser->StartParse(pFileAccess, std::move(pDocument));
if (error != CPDF_Parser::SUCCESS) {
- delete pParser;
ProcessParseError(error);
return nullptr;
}
#ifdef PDF_ENABLE_XFA
- CPDF_Document* pPDFDoc = pParser->GetDocument();
+ CPDF_Document* pPDFDoc = pParser.release()->GetDocument();
if (!pPDFDoc)
return nullptr;
CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
return new CPDFXFA_Document(pPDFDoc, pProvider);
#else // PDF_ENABLE_XFA
- return pParser->GetDocument();
+ return pParser.release()->GetDocument();
#endif // PDF_ENABLE_XFA
}
@@ -446,35 +447,36 @@ class CMemFile final : public IFX_FileRead {
DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf,
int size,
FPDF_BYTESTRING password) {
- CPDF_Parser* pParser = new CPDF_Parser;
- pParser->SetPassword(password);
CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size);
- CPDF_Parser::Error error = pParser->StartParse(pMemFile);
+ std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser);
+ pParser->SetPassword(password);
+
+ std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get()));
+ CPDF_Parser::Error error =
+ pParser->StartParse(pMemFile, std::move(pDocument));
if (error != CPDF_Parser::SUCCESS) {
- delete pParser;
ProcessParseError(error);
return nullptr;
}
- CPDF_Document* pDoc = pParser ? pParser->GetDocument() : nullptr;
- CheckUnSupportError(pDoc, error);
- return FPDFDocumentFromCPDFDocument(pParser->GetDocument());
+ CheckUnSupportError(pParser->GetDocument(), error);
+ return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument());
}
DLLEXPORT FPDF_DOCUMENT STDCALL
FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess,
FPDF_BYTESTRING password) {
- CPDF_Parser* pParser = new CPDF_Parser;
- pParser->SetPassword(password);
CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess);
- CPDF_Parser::Error error = pParser->StartParse(pFile);
+ std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser);
+ pParser->SetPassword(password);
+
+ std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get()));
+ CPDF_Parser::Error error = pParser->StartParse(pFile, std::move(pDocument));
if (error != CPDF_Parser::SUCCESS) {
- delete pParser;
ProcessParseError(error);
return nullptr;
}
- CPDF_Document* pDoc = pParser ? pParser->GetDocument() : nullptr;
- CheckUnSupportError(pDoc, error);
- return FPDFDocumentFromCPDFDocument(pParser->GetDocument());
+ CheckUnSupportError(pParser->GetDocument(), error);
+ return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument());
}
DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,