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

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

Issue 2158023002: Pdfium: Fix fonts leaking on ClosePage. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix crash. Created 4 years, 5 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 "core/fpdfapi/fpdf_page/pageint.h" 7 #include "core/fpdfapi/fpdf_page/pageint.h"
8 8
9 #include "core/fdrm/crypto/include/fx_crypt.h" 9 #include "core/fdrm/crypto/include/fx_crypt.h"
10 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" 10 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 if (!pFontDict) 207 if (!pFontDict)
208 return; 208 return;
209 209
210 auto it = m_FontMap.find(pFontDict); 210 auto it = m_FontMap.find(pFontDict);
211 if (it == m_FontMap.end()) 211 if (it == m_FontMap.end())
212 return; 212 return;
213 213
214 CPDF_CountedFont* fontData = it->second; 214 CPDF_CountedFont* fontData = it->second;
215 if (fontData->get()) { 215 if (fontData->get()) {
216 fontData->RemoveRef(); 216 fontData->RemoveRef();
217 if (fontData->use_count() == 0) { 217 if (fontData->use_count() == 1) {
218 // We have font data only in m_FontMap cache. Clean it.
218 fontData->clear(); 219 fontData->clear();
219 } 220 }
220 } 221 }
221 } 222 }
222 223
223 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace( 224 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(
224 CPDF_Object* pCSObj, 225 CPDF_Object* pCSObj,
225 const CPDF_Dictionary* pResources) { 226 const CPDF_Dictionary* pResources) {
226 std::set<CPDF_Object*> visited; 227 std::set<CPDF_Object*> visited;
227 return GetColorSpaceImpl(pCSObj, pResources, &visited); 228 return GetColorSpaceImpl(pCSObj, pResources, &visited);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (!pColorSpace) 322 if (!pColorSpace)
322 return; 323 return;
323 324
324 auto it = m_ColorSpaceMap.find(pColorSpace); 325 auto it = m_ColorSpaceMap.find(pColorSpace);
325 if (it == m_ColorSpaceMap.end()) 326 if (it == m_ColorSpaceMap.end())
326 return; 327 return;
327 328
328 CPDF_CountedColorSpace* csData = it->second; 329 CPDF_CountedColorSpace* csData = it->second;
329 if (csData->get()) { 330 if (csData->get()) {
330 csData->RemoveRef(); 331 csData->RemoveRef();
331 if (csData->use_count() == 0) { 332 if (csData->use_count() == 1) {
333 // We have item only in m_ColorSpaceMap cache. Clean it.
332 csData->get()->ReleaseCS(); 334 csData->get()->ReleaseCS();
333 csData->reset(nullptr); 335 csData->reset(nullptr);
334 } 336 }
335 } 337 }
336 } 338 }
337 339
338 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, 340 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj,
339 FX_BOOL bShading, 341 FX_BOOL bShading,
340 const CFX_Matrix& matrix) { 342 const CFX_Matrix& matrix) {
341 if (!pPatternObj) 343 if (!pPatternObj)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 if (!pPatternObj) 382 if (!pPatternObj)
381 return; 383 return;
382 384
383 auto it = m_PatternMap.find(pPatternObj); 385 auto it = m_PatternMap.find(pPatternObj);
384 if (it == m_PatternMap.end()) 386 if (it == m_PatternMap.end())
385 return; 387 return;
386 388
387 CPDF_CountedPattern* ptData = it->second; 389 CPDF_CountedPattern* ptData = it->second;
388 if (ptData->get()) { 390 if (ptData->get()) {
389 ptData->RemoveRef(); 391 ptData->RemoveRef();
390 if (ptData->use_count() == 0) { 392 if (ptData->use_count() == 1) {
393 // We have item only in m_PatternMap cache. Clean it.
391 ptData->clear(); 394 ptData->clear();
392 } 395 }
393 } 396 }
394 } 397 }
395 398
396 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) { 399 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) {
397 if (!pImageStream) 400 if (!pImageStream)
398 return nullptr; 401 return nullptr;
399 402
400 const uint32_t dwImageObjNum = pImageStream->GetObjNum(); 403 const uint32_t dwImageObjNum = pImageStream->GetObjNum();
(...skipping 16 matching lines...) Expand all
417 420
418 auto it = m_ImageMap.find(pImageStream->GetObjNum()); 421 auto it = m_ImageMap.find(pImageStream->GetObjNum());
419 if (it == m_ImageMap.end()) 422 if (it == m_ImageMap.end())
420 return; 423 return;
421 424
422 CPDF_CountedImage* image = it->second; 425 CPDF_CountedImage* image = it->second;
423 if (!image) 426 if (!image)
424 return; 427 return;
425 428
426 image->RemoveRef(); 429 image->RemoveRef();
427 if (image->use_count() == 0) { 430 if (image->use_count() == 1) {
431 // We have item only in m_ImageMap cache. Clean it.
428 delete image->get(); 432 delete image->get();
429 delete image; 433 delete image;
430 m_ImageMap.erase(it); 434 m_ImageMap.erase(it);
431 } 435 }
432 } 436 }
433 437
434 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile( 438 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile(
435 CPDF_Stream* pIccProfileStream) { 439 CPDF_Stream* pIccProfileStream) {
436 if (!pIccProfileStream) 440 if (!pIccProfileStream)
437 return nullptr; 441 return nullptr;
438 442
439 auto it = m_IccProfileMap.find(pIccProfileStream); 443 auto it = m_IccProfileMap.find(pIccProfileStream);
440 if (it != m_IccProfileMap.end()) { 444 if (it != m_IccProfileMap.end()) {
441 return it->second->AddRef(); 445 return it->second->AddRef();
442 } 446 }
443 447
444 CPDF_StreamAcc stream; 448 CPDF_StreamAcc stream;
445 stream.LoadAllData(pIccProfileStream, FALSE); 449 stream.LoadAllData(pIccProfileStream, FALSE);
446 uint8_t digest[20]; 450 uint8_t digest[20];
447 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); 451 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest);
448 CFX_ByteString bsDigest(digest, 20); 452 CFX_ByteString bsDigest(digest, 20);
449 auto hash_it = m_HashProfileMap.find(bsDigest); 453 auto hash_it = m_HashProfileMap.find(bsDigest);
450 if (hash_it != m_HashProfileMap.end()) { 454 if (hash_it != m_HashProfileMap.end()) {
451 auto it_copied_stream = m_IccProfileMap.find(hash_it->second); 455 auto it_copied_stream = m_IccProfileMap.find(hash_it->second);
452 return it_copied_stream->second->AddRef(); 456 if (it_copied_stream != m_IccProfileMap.end())
dsinclair 2016/07/18 20:13:48 Should we be removing the entry from IccProfileMap
snake 2016/07/19 18:55:14 No, To remove it, we should walk within full m_Icc
457 return it_copied_stream->second->AddRef();
453 } 458 }
454 CPDF_IccProfile* pProfile = 459 CPDF_IccProfile* pProfile =
455 new CPDF_IccProfile(stream.GetData(), stream.GetSize()); 460 new CPDF_IccProfile(stream.GetData(), stream.GetSize());
456 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); 461 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile);
457 m_IccProfileMap[pIccProfileStream] = ipData; 462 m_IccProfileMap[pIccProfileStream] = ipData;
458 m_HashProfileMap[bsDigest] = pIccProfileStream; 463 m_HashProfileMap[bsDigest] = pIccProfileStream;
459 return ipData->AddRef(); 464 return ipData->AddRef();
460 } 465 }
461 466
462 void CPDF_DocPageData::ReleaseIccProfile(CPDF_IccProfile* pIccProfile) { 467 void CPDF_DocPageData::ReleaseIccProfile(CPDF_IccProfile* pIccProfile) {
463 ASSERT(pIccProfile); 468 ASSERT(pIccProfile);
464 469
465 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) { 470 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) {
466 CPDF_CountedIccProfile* profile = it->second; 471 CPDF_CountedIccProfile* profile = it->second;
467 if (profile->get() != pIccProfile) 472 if (profile->get() != pIccProfile)
468 continue; 473 continue;
469 474
470 profile->RemoveRef(); 475 profile->RemoveRef();
471 if (profile->use_count() == 0) { 476 if (profile->use_count() == 1) {
477 // We have item only in m_IccProfileMap cache. Clean it.
472 delete profile->get(); 478 delete profile->get();
473 delete profile; 479 delete profile;
474 m_IccProfileMap.erase(it); 480 m_IccProfileMap.erase(it);
475 return; 481 return;
476 } 482 }
477 } 483 }
478 } 484 }
479 485
480 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc( 486 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(
481 CPDF_Stream* pFontStream) { 487 CPDF_Stream* pFontStream) {
(...skipping 25 matching lines...) Expand all
507 513
508 auto it = m_FontFileMap.find(pFontStream); 514 auto it = m_FontFileMap.find(pFontStream);
509 if (it == m_FontFileMap.end()) 515 if (it == m_FontFileMap.end())
510 return; 516 return;
511 517
512 CPDF_CountedStreamAcc* findData = it->second; 518 CPDF_CountedStreamAcc* findData = it->second;
513 if (!findData) 519 if (!findData)
514 return; 520 return;
515 521
516 findData->RemoveRef(); 522 findData->RemoveRef();
517 if (findData->use_count() == 0 || bForce) { 523 if (findData->use_count() == 1 || bForce) {
524 // We have item only in m_FontFileMap cache. Clean it.
518 delete findData->get(); 525 delete findData->get();
519 delete findData; 526 delete findData;
520 m_FontFileMap.erase(it); 527 m_FontFileMap.erase(it);
521 } 528 }
522 } 529 }
523 530
524 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr( 531 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(
525 CPDF_Object* pCSObj) const { 532 CPDF_Object* pCSObj) const {
526 if (!pCSObj) 533 if (!pCSObj)
527 return nullptr; 534 return nullptr;
528 535
529 auto it = m_ColorSpaceMap.find(pCSObj); 536 auto it = m_ColorSpaceMap.find(pCSObj);
530 return it != m_ColorSpaceMap.end() ? it->second : nullptr; 537 return it != m_ColorSpaceMap.end() ? it->second : nullptr;
531 } 538 }
532 539
533 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( 540 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(
534 CPDF_Object* pPatternObj) const { 541 CPDF_Object* pPatternObj) const {
535 if (!pPatternObj) 542 if (!pPatternObj)
536 return nullptr; 543 return nullptr;
537 544
538 auto it = m_PatternMap.find(pPatternObj); 545 auto it = m_PatternMap.find(pPatternObj);
539 return it != m_PatternMap.end() ? it->second : nullptr; 546 return it != m_PatternMap.end() ? it->second : nullptr;
540 } 547 }
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