Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1423)

Unified Diff: core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp

Issue 656753002: Store the address of the page data map's value for proper referencing. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Store counted objects as member Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index 8e578f6f8f2eb0d6bb7b49f876ee48c5c3525a20..44915cc10865d9a3bd44facd23b52b8f24db3f77 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -147,15 +147,53 @@ CPDF_DocPageData::~CPDF_DocPageData()
{
Clear(FALSE);
Clear(TRUE);
+ FX_POSITION pos = NULL;
Tom Sepez 2014/10/14 23:07:44 nit: no need to initialize since we assign in the
+ pos = m_PatternMap.GetStartPosition();
Tom Sepez 2014/10/14 23:07:44 nit: for future cleanup, there should be a method
+ while (pos)
+ {
+ CPDF_Object* ptObj;
+ CPDF_CountedObject<CPDF_Pattern*>* ptData;
+ m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
+ delete ptData;
+ }
+ m_PatternMap.RemoveAll();
+ pos = m_FontMap.GetStartPosition();
+ while (pos)
+ {
+ CPDF_Dictionary* fontDict;
+ CPDF_CountedObject<CPDF_Font*>* fontData;
+ m_FontMap.GetNextAssoc(pos, fontDict, fontData);
+ delete fontData;
+ }
+ m_FontMap.RemoveAll();
+ pos = m_ColorSpaceMap.GetStartPosition();
+ while (pos)
+ {
+ CPDF_Object* csKey;
+ CPDF_CountedObject<CPDF_ColorSpace*>* csData;
+ m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData);
+ delete csData;
+ }
+ m_ColorSpaceMap.RemoveAll();
}
void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
{
FX_POSITION pos;
-
m_bForceClear = bForceRelease;
-
- // Release objects saved in the resource maps like font map and color space map.
- // The compound objects shall be released before simple ones.
+ pos = m_PatternMap.GetStartPosition();
+ while (pos) {
Tom Sepez 2014/10/14 23:07:44 nit: for future cleanup, again this should be a me
+ CPDF_Object* ptObj;
+ CPDF_CountedObject<CPDF_Pattern*>* ptData;
+ m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
+ if (!ptData->m_Obj) {
+ continue;
+ }
+ if (bForceRelease || ptData->m_nCount < 2) {
+ ptData->m_Obj->SetForceClear(bForceRelease);
+ delete ptData->m_Obj;
+ ptData->m_Obj = NULL;
+ }
+ }
pos = m_FontMap.GetStartPosition();
while (pos) {
CPDF_Dictionary* fontDict;
@@ -203,7 +241,6 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
}
}
delete ipData->m_Obj;
- ipData->m_Obj = NULL;
delete ipData;
Tom Sepez 2014/10/14 23:07:44 Not clear to me why some of these delete their cou
Bo Xu 2014/10/14 23:37:49 For colorspace, pattern and font which are managed
m_IccProfileMap.RemoveKey(ipKey);
}
@@ -218,25 +255,10 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
}
if (bForceRelease || ftData->m_nCount < 2) {
delete ftData->m_Obj;
- ftData->m_Obj = NULL;
delete ftData;
m_FontFileMap.RemoveKey(ftKey);
}
}
- pos = m_PatternMap.GetStartPosition();
- while (pos) {
- CPDF_Object* ptObj;
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
- if (!ptData->m_Obj) {
- continue;
- }
- if (bForceRelease || ptData->m_nCount < 2) {
- ptData->m_Obj->SetForceClear(bForceRelease);
- delete ptData->m_Obj;
- ptData->m_Obj = NULL;
- }
- }
pos = m_ImageMap.GetStartPosition();
while (pos) {
FX_DWORD objNum;
@@ -247,7 +269,6 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
}
if (bForceRelease || imageData->m_nCount < 2) {
delete imageData->m_Obj;
- imageData->m_Obj = NULL;
delete imageData;
m_ImageMap.RemoveKey(objNum);
}
@@ -653,4 +674,24 @@ void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO
return;
}
PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontStream, NULL, bForce);
+}
+CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(CPDF_Object* pCSObj) const
Tom Sepez 2014/10/14 23:07:44 nit: Again, this might be a method of the templat
+{
+ if (!pCSObj) return NULL;
+ CPDF_CountedObject<CPDF_ColorSpace*>* csData;
+ if (m_ColorSpaceMap.Lookup(pCSObj, csData))
+ {
+ return csData;
+ }
+ return NULL;
}
+CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(CPDF_Object* pPatternObj) const
+{
+ if (!pPatternObj) return NULL;
+ CPDF_CountedObject<CPDF_Pattern*>* ptData;
+ if (m_PatternMap.Lookup(pPatternObj, ptData))
+ {
+ return ptData;
+ }
+ return NULL;
+}

Powered by Google App Engine
This is Rietveld 408576698