diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-04-27 19:32:59 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-27 19:32:59 +0000 |
commit | 862cbe46b7d7040e35733f5ed63839ee34223387 (patch) | |
tree | 45895d00a62941d48311734c5244d0d1ecf34d56 /fpdfsdk/cpdfsdk_helpers.cpp | |
parent | 2b053ce82e921984ee191b26fe9a760ba1508a66 (diff) | |
download | pdfium-862cbe46b7d7040e35733f5ed63839ee34223387.tar.xz |
Avoid potential duplicate unique_ptr to CPDF_Document from CPDFXA_Context.
Should FPDFDocumentFromCPDFDocument() be called several times under
XFA, we may WrapUnique() the document several times. So cache a pointer
back from CPDF_Document to CPDFXFA_Context to avoid this.
Because of layering, introduce a placeholder type CPDF_Document::Extension.
This is actually the first step in some larger XFA ownership cleanup, but
makes a nice standalone CL around the one particular issue.
Change-Id: I4be326ddb1a5fae7339e6ed6745dd551b1374b53
Reviewed-on: https://pdfium-review.googlesource.com/31570
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/cpdfsdk_helpers.cpp')
-rw-r--r-- | fpdfsdk/cpdfsdk_helpers.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp index 4c417e15e5..040b0f2e5a 100644 --- a/fpdfsdk/cpdfsdk_helpers.cpp +++ b/fpdfsdk/cpdfsdk_helpers.cpp @@ -166,9 +166,12 @@ CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { #ifdef PDF_ENABLE_XFA - return doc ? FPDFDocumentFromUnderlying( - new CPDFXFA_Context(pdfium::WrapUnique(doc))) - : nullptr; + if (!doc) + return nullptr; + if (!doc->GetExtension()) + doc->SetExtension(new CPDFXFA_Context(pdfium::WrapUnique(doc))); + return FPDFDocumentFromUnderlying( + static_cast<CPDFXFA_Context*>(doc->GetExtension())); #else // PDF_ENABLE_XFA return FPDFDocumentFromUnderlying(doc); #endif // PDF_ENABLE_XFA |