summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_dataavail.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-08-24 11:12:19 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-24 11:12:19 -0700
commitcedaa557316a3f5c436814e69d67f19795f471d7 (patch)
tree128140994288bcd5b01f578e9dafc4bf1ea87493 /fpdfsdk/fpdf_dataavail.cpp
parentade4b495433751ac853f2d677b9e1da94d0d6bf7 (diff)
downloadpdfium-cedaa557316a3f5c436814e69d67f19795f471d7.tar.xz
Flip document and parser ownership
This Cl switches the ownership between the parser and the document. Previously the parser owned the document and we'd jump through hoops during cleanup to delete the right object. This Cl flips the ownership so the document owns the parser and simplifies the cleanup logic where needed. BUG=pdfium:565 Review-Url: https://codereview.chromium.org/2275773003
Diffstat (limited to 'fpdfsdk/fpdf_dataavail.cpp')
-rw-r--r--fpdfsdk/fpdf_dataavail.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp
index 5dd42402ed..7b9ba32fb0 100644
--- a/fpdfsdk/fpdf_dataavail.cpp
+++ b/fpdfsdk/fpdf_dataavail.cpp
@@ -139,16 +139,17 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) {
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->StartLinearizedParse(
- pDataAvail->m_pDataAvail->GetFileRead(), std::move(pDocument));
+ std::unique_ptr<CPDF_Document> pDocument(
+ new CPDF_Document(std::move(pParser)));
+ CPDF_Parser::Error error = pDocument->GetParser()->StartLinearizedParse(
+ pDataAvail->m_pDataAvail->GetFileRead(), pDocument.get());
if (error != CPDF_Parser::SUCCESS) {
ProcessParseError(error);
return nullptr;
}
- pDataAvail->m_pDataAvail->SetDocument(pParser->GetDocument());
- CheckUnSupportError(pParser->GetDocument(), FPDF_ERR_SUCCESS);
- return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument());
+ pDataAvail->m_pDataAvail->SetDocument(pDocument.get());
+ CheckUnSupportError(pDocument.get(), FPDF_ERR_SUCCESS);
+ return FPDFDocumentFromCPDFDocument(pDocument.release());
}
DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc) {