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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp

Issue 582993002: Adjust the order of clearing resource in CPDF_DocPageData::Clear (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fpdfapi/fpdf_page.h" 7 #include "../../../include/fpdfapi/fpdf_page.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fdrm/fx_crypt.h" 9 #include "../../../include/fdrm/fx_crypt.h"
10 #include "../fpdf_font/font_int.h" 10 #include "../fpdf_font/font_int.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 m_FontFileMap.InitHashTable(32); 144 m_FontFileMap.InitHashTable(32);
145 } 145 }
146 CPDF_DocPageData::~CPDF_DocPageData() 146 CPDF_DocPageData::~CPDF_DocPageData()
147 { 147 {
148 Clear(FALSE); 148 Clear(FALSE);
149 Clear(TRUE); 149 Clear(TRUE);
150 } 150 }
151 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) 151 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
152 { 152 {
153 FX_POSITION pos; 153 FX_POSITION pos;
154 FX_DWORD nCount; 154 FX_DWORD nCount;
Tom Sepez 2014/09/19 17:40:38 In fact, we can remove the nCount local entirely,
155 155
156 m_bForceClear = bForceRelease; 156 m_bForceClear = bForceRelease;
157 pos = m_FontMap.GetStartPosition(); 157 pos = m_FontMap.GetStartPosition();
Tom Sepez 2014/09/19 17:36:31 Nit: need a small comment here explaining that com
158 while (pos) { 158 while (pos) {
159 CPDF_Dictionary* fontDict; 159 CPDF_Dictionary* fontDict;
160 CPDF_CountedObject<CPDF_Font*>* fontData; 160 CPDF_CountedObject<CPDF_Font*>* fontData;
161 m_FontMap.GetNextAssoc(pos, fontDict, fontData); 161 m_FontMap.GetNextAssoc(pos, fontDict, fontData);
162 nCount = fontData->m_nCount; 162 nCount = fontData->m_nCount;
163 if (bForceRelease || nCount < 2) { 163 if (bForceRelease || nCount < 2) {
164 delete fontData->m_Obj; 164 delete fontData->m_Obj;
165 fontData->m_Obj = NULL; 165 fontData->m_Obj = NULL;
166 } 166 }
167 } 167 }
168 pos = m_ImageMap.GetStartPosition();
169 while (pos) {
170 FX_DWORD objNum;
171 CPDF_CountedObject<CPDF_Image*>* imageData;
172 m_ImageMap.GetNextAssoc(pos, objNum, imageData);
173 nCount = imageData->m_nCount;
174 if (bForceRelease || nCount < 2) {
175 delete imageData->m_Obj;
176 delete imageData;
177 m_ImageMap.RemoveKey(objNum);
178 }
179 }
180 pos = m_ColorSpaceMap.GetStartPosition(); 168 pos = m_ColorSpaceMap.GetStartPosition();
181 while (pos) { 169 while (pos) {
182 CPDF_Object* csKey; 170 CPDF_Object* csKey;
183 CPDF_CountedObject<CPDF_ColorSpace*>* csData; 171 CPDF_CountedObject<CPDF_ColorSpace*>* csData;
184 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); 172 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData);
185 nCount = csData->m_nCount; 173 nCount = csData->m_nCount;
186 if (bForceRelease || nCount < 2) { 174 if (bForceRelease || nCount < 2) {
187 csData->m_Obj->ReleaseCS(); 175 csData->m_Obj->ReleaseCS();
188 csData->m_Obj = NULL; 176 csData->m_Obj = NULL;
189 } 177 }
(...skipping 30 matching lines...) Expand all
220 delete ftData->m_Obj; 208 delete ftData->m_Obj;
221 delete ftData; 209 delete ftData;
222 m_FontFileMap.RemoveKey(ftKey); 210 m_FontFileMap.RemoveKey(ftKey);
223 } 211 }
224 } 212 }
225 pos = m_PatternMap.GetStartPosition(); 213 pos = m_PatternMap.GetStartPosition();
226 while (pos) { 214 while (pos) {
227 CPDF_Object* ptObj; 215 CPDF_Object* ptObj;
228 CPDF_CountedObject<CPDF_Pattern*>* ptData; 216 CPDF_CountedObject<CPDF_Pattern*>* ptData;
229 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); 217 m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
230 nCount = ptData->m_nCount; 218 nCount = ptData->m_nCount;
Tom Sepez 2014/09/19 17:36:31 nit: if ptObj->m_obj is NULL, we can short-circuit
231 if (bForceRelease || nCount < 2) { 219 if (bForceRelease || nCount < 2) {
232 ptData->m_Obj->SetForceClear(bForceRelease); 220 if (ptData->m_Obj) {
233 delete ptData->m_Obj; 221 ptData->m_Obj->SetForceClear(bForceRelease);
234 ptData->m_Obj = NULL; 222 delete ptData->m_Obj;
223 ptData->m_Obj = NULL;
224 }
225 }
226 }
227 pos = m_ImageMap.GetStartPosition();
228 while (pos) {
229 FX_DWORD objNum;
230 CPDF_CountedObject<CPDF_Image*>* imageData;
231 m_ImageMap.GetNextAssoc(pos, objNum, imageData);
232 nCount = imageData->m_nCount;
233 if (bForceRelease || nCount < 2) {
234 delete imageData->m_Obj;
Tom Sepez 2014/09/19 17:36:31 do we need to check imageData->m_obj for NULLness
235 delete imageData;
236 m_ImageMap.RemoveKey(objNum);
235 } 237 }
236 } 238 }
237 } 239 }
238 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl y) 240 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl y)
239 { 241 {
240 if (!pFontDict) { 242 if (!pFontDict) {
241 return NULL; 243 return NULL;
242 } 244 }
243 if (findOnly) { 245 if (findOnly) {
244 CPDF_CountedObject<CPDF_Font*>* fontData; 246 CPDF_CountedObject<CPDF_Font*>* fontData;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 m_FontFileMap.SetAt(pFontStream, ftData); 631 m_FontFileMap.SetAt(pFontStream, ftData);
630 return pFontFile; 632 return pFontFile;
631 } 633 }
632 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO L bForce) 634 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO L bForce)
633 { 635 {
634 if (!pFontStream) { 636 if (!pFontStream) {
635 return; 637 return;
636 } 638 }
637 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS tream, NULL, bForce); 639 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS tream, NULL, bForce);
638 } 640 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698