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

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;
155 154
156 m_bForceClear = bForceRelease; 155 m_bForceClear = bForceRelease;
156
157 // Release objects saved in the resource maps like font map and color space map.
158 // The compound objects shall be released before simple ones.
157 pos = m_FontMap.GetStartPosition(); 159 pos = m_FontMap.GetStartPosition();
158 while (pos) { 160 while (pos) {
159 CPDF_Dictionary* fontDict; 161 CPDF_Dictionary* fontDict;
160 CPDF_CountedObject<CPDF_Font*>* fontData; 162 CPDF_CountedObject<CPDF_Font*>* fontData;
161 m_FontMap.GetNextAssoc(pos, fontDict, fontData); 163 m_FontMap.GetNextAssoc(pos, fontDict, fontData);
162 nCount = fontData->m_nCount; 164 if (!fontData->m_Obj) {
163 if (bForceRelease || nCount < 2) { 165 continue;
166 }
167 if (bForceRelease || fontData->m_nCount < 2) {
164 delete fontData->m_Obj; 168 delete fontData->m_Obj;
165 fontData->m_Obj = NULL; 169 fontData->m_Obj = NULL;
166 } 170 }
167 } 171 }
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(); 172 pos = m_ColorSpaceMap.GetStartPosition();
181 while (pos) { 173 while (pos) {
182 CPDF_Object* csKey; 174 CPDF_Object* csKey;
183 CPDF_CountedObject<CPDF_ColorSpace*>* csData; 175 CPDF_CountedObject<CPDF_ColorSpace*>* csData;
184 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); 176 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData);
185 nCount = csData->m_nCount; 177 if (!csData->m_Obj) {
186 if (bForceRelease || nCount < 2) { 178 continue;
179 }
180 if (bForceRelease || csData->m_nCount < 2) {
181 // csData->m_Obj is deleted in the function of ReleaseCS().
187 csData->m_Obj->ReleaseCS(); 182 csData->m_Obj->ReleaseCS();
188 csData->m_Obj = NULL; 183 csData->m_Obj = NULL;
189 } 184 }
190 } 185 }
191 pos = m_IccProfileMap.GetStartPosition(); 186 pos = m_IccProfileMap.GetStartPosition();
192 while (pos) { 187 while (pos) {
193 CPDF_Stream* ipKey; 188 CPDF_Stream* ipKey;
194 CPDF_CountedObject<CPDF_IccProfile*>* ipData; 189 CPDF_CountedObject<CPDF_IccProfile*>* ipData;
195 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData); 190 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData);
196 nCount = ipData->m_nCount; 191 if (!ipData->m_Obj) {
197 if (bForceRelease || nCount < 2) { 192 continue;
193 }
194 if (bForceRelease || ipData->m_nCount < 2) {
198 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition(); 195 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition();
199 while (pos2) { 196 while (pos2) {
200 CFX_ByteString bsKey; 197 CFX_ByteString bsKey;
201 CPDF_Stream* pFindStream = NULL; 198 CPDF_Stream* pFindStream = NULL;
202 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream); 199 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream);
203 if (ipKey == pFindStream) { 200 if (ipKey == pFindStream) {
204 m_HashProfileMap.RemoveKey(bsKey); 201 m_HashProfileMap.RemoveKey(bsKey);
205 break; 202 break;
206 } 203 }
207 } 204 }
208 delete ipData->m_Obj; 205 delete ipData->m_Obj;
206 ipData->m_Obj = NULL;
209 delete ipData; 207 delete ipData;
210 m_IccProfileMap.RemoveKey(ipKey); 208 m_IccProfileMap.RemoveKey(ipKey);
211 } 209 }
212 } 210 }
213 pos = m_FontFileMap.GetStartPosition(); 211 pos = m_FontFileMap.GetStartPosition();
214 while (pos) { 212 while (pos) {
215 CPDF_Stream* ftKey; 213 CPDF_Stream* ftKey;
216 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; 214 CPDF_CountedObject<CPDF_StreamAcc*>* ftData;
217 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); 215 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData);
218 nCount = ftData->m_nCount; 216 if (!ftData->m_Obj) {
219 if (bForceRelease || nCount < 2) { 217 continue;
218 }
219 if (bForceRelease || ftData->m_nCount < 2) {
220 delete ftData->m_Obj; 220 delete ftData->m_Obj;
221 ftData->m_Obj = NULL;
221 delete ftData; 222 delete ftData;
222 m_FontFileMap.RemoveKey(ftKey); 223 m_FontFileMap.RemoveKey(ftKey);
223 } 224 }
224 } 225 }
225 pos = m_PatternMap.GetStartPosition(); 226 pos = m_PatternMap.GetStartPosition();
226 while (pos) { 227 while (pos) {
227 CPDF_Object* ptObj; 228 CPDF_Object* ptObj;
228 CPDF_CountedObject<CPDF_Pattern*>* ptData; 229 CPDF_CountedObject<CPDF_Pattern*>* ptData;
229 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); 230 m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
230 nCount = ptData->m_nCount; 231 if (!ptData->m_Obj) {
231 if (bForceRelease || nCount < 2) { 232 continue;
233 }
234 if (bForceRelease || ptData->m_nCount < 2) {
232 ptData->m_Obj->SetForceClear(bForceRelease); 235 ptData->m_Obj->SetForceClear(bForceRelease);
233 delete ptData->m_Obj; 236 delete ptData->m_Obj;
234 ptData->m_Obj = NULL; 237 ptData->m_Obj = NULL;
235 } 238 }
236 } 239 }
240 pos = m_ImageMap.GetStartPosition();
241 while (pos) {
242 FX_DWORD objNum;
243 CPDF_CountedObject<CPDF_Image*>* imageData;
244 m_ImageMap.GetNextAssoc(pos, objNum, imageData);
245 if (!imageData->m_Obj) {
246 continue;
247 }
248 if (bForceRelease || imageData->m_nCount < 2) {
249 delete imageData->m_Obj;
250 imageData->m_Obj = NULL;
251 delete imageData;
252 m_ImageMap.RemoveKey(objNum);
253 }
254 }
237 } 255 }
238 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl y) 256 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl y)
239 { 257 {
240 if (!pFontDict) { 258 if (!pFontDict) {
241 return NULL; 259 return NULL;
242 } 260 }
243 if (findOnly) { 261 if (findOnly) {
244 CPDF_CountedObject<CPDF_Font*>* fontData; 262 CPDF_CountedObject<CPDF_Font*>* fontData;
245 if (m_FontMap.Lookup(pFontDict, fontData)) { 263 if (m_FontMap.Lookup(pFontDict, fontData)) {
246 if (!fontData->m_Obj) { 264 if (!fontData->m_Obj) {
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 m_FontFileMap.SetAt(pFontStream, ftData); 647 m_FontFileMap.SetAt(pFontStream, ftData);
630 return pFontFile; 648 return pFontFile;
631 } 649 }
632 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO L bForce) 650 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO L bForce)
633 { 651 {
634 if (!pFontStream) { 652 if (!pFontStream) {
635 return; 653 return;
636 } 654 }
637 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS tream, NULL, bForce); 655 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS tream, NULL, bForce);
638 } 656 }
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