diff options
author | Bo Xu <bo_xu@foxitsoftware.com> | 2014-09-09 18:39:30 -0700 |
---|---|---|
committer | Bo Xu <bo_xu@foxitsoftware.com> | 2014-09-29 10:22:23 -0700 |
commit | e7e9da54a57f73b995b8aa213a675de7fcdc61cf (patch) | |
tree | 12b4f52f386920b2b9fd9e2af55d1610e662fc71 | |
parent | 539ea4562e71429066358fcaa660259813c817ed (diff) | |
download | pdfium-e7e9da54a57f73b995b8aa213a675de7fcdc61cf.tar.xz |
Change the forced clear order of CPDF_DocPageData::Clear, and remove m_pDocument in CPDF_Color
If not forced clear, the counter of CPDF_Pattern will take care the count of referenced instance.
When forced clear, clear color first to make sure pattern still exists when referencing it.
BUG=411154
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/554913003
-rw-r--r-- | core/include/fpdfapi/fpdf_resource.h | 6 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 13 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 22 |
3 files changed, 21 insertions, 20 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h index 4ce4ddc8bb..25256fa86a 100644 --- a/core/include/fpdfapi/fpdf_resource.h +++ b/core/include/fpdfapi/fpdf_resource.h @@ -680,10 +680,8 @@ class CPDF_Color : public CFX_Object { public: - CPDF_Color() + CPDF_Color() :m_pCS(NULL), m_pBuffer(NULL) { - m_pBuffer = NULL; - m_pCS = NULL; } CPDF_Color(int family); @@ -720,10 +718,10 @@ public: CPDF_ColorSpace* m_pCS; - FX_FLOAT* m_pBuffer; protected: void ReleaseBuffer(); void ReleaseColorSpace(); + FX_FLOAT* m_pBuffer; }; #define PATTERN_TILING 1 #define PATTERN_SHADING 2 diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index cf6dec51df..4f619da961 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -1289,8 +1289,10 @@ void CPDF_Color::ReleaseBuffer() PatternValue* pvalue = (PatternValue*)m_pBuffer; CPDF_Pattern* pPattern = pvalue->m_pPattern; if (pPattern && pPattern->m_pDocument) { - pPattern->SaveColor(NULL); - pPattern->m_pDocument->GetPageData()->ReleasePattern(pPattern->m_pPatternObj); + CPDF_DocPageData *pPageData = pPattern->m_pDocument->GetPageData(); + if (pPageData && !pPageData->IsForceClear()) { + pPageData->ReleasePattern(pPattern->m_pPatternObj); + } } } FX_Free(m_pBuffer); @@ -1345,9 +1347,10 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) CPDF_DocPageData* pDocPageData = NULL; PatternValue* pvalue = (PatternValue*)m_pBuffer; if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) { - pDocPageData = pvalue->m_pPattern->m_pDocument->GetPageData(); - pvalue->m_pPattern->SaveColor(NULL); - pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj); + CPDF_DocPageData *pDocPageData = pvalue->m_pPattern->m_pDocument->GetPageData(); + if (pDocPageData && !pDocPageData->IsForceClear()) { + pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj); + } } pvalue->m_nComps = ncomps; pvalue->m_pPattern = pPattern; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index 16f0a9cfad..131edbe9b5 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -154,17 +154,6 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) FX_DWORD nCount; m_bForceClear = bForceRelease; - pos = m_PatternMap.GetStartPosition(); - while (pos) { - CPDF_Object* ptObj; - CPDF_CountedObject<CPDF_Pattern*>* ptData; - m_PatternMap.GetNextAssoc(pos, ptObj, ptData); - nCount = ptData->m_nCount; - if (bForceRelease || nCount < 2) { - delete ptData->m_Obj; - ptData->m_Obj = NULL; - } - } pos = m_FontMap.GetStartPosition(); while (pos) { CPDF_Dictionary* fontDict; @@ -233,6 +222,17 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) m_FontFileMap.RemoveKey(ftKey); } } + pos = m_PatternMap.GetStartPosition(); + while (pos) { + CPDF_Object* ptObj; + CPDF_CountedObject<CPDF_Pattern*>* ptData; + m_PatternMap.GetNextAssoc(pos, ptObj, ptData); + nCount = ptData->m_nCount; + if (bForceRelease || nCount < 2) { + delete ptData->m_Obj; + ptData->m_Obj = NULL; + } + } } CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnly) { |