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

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

Issue 2350763002: Revert of Pdfium: Fix fonts leaking on ClosePage. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 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 | core/fpdfapi/fpdf_parser/cpdf_document.cpp » ('j') | 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 <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 auto it = m_FontMap.find(pFontDict); 208 auto it = m_FontMap.find(pFontDict);
209 if (it == m_FontMap.end()) 209 if (it == m_FontMap.end())
210 return; 210 return;
211 211
212 CPDF_CountedFont* pFontData = it->second; 212 CPDF_CountedFont* pFontData = it->second;
213 if (!pFontData->get()) 213 if (!pFontData->get())
214 return; 214 return;
215 215
216 pFontData->RemoveRef(); 216 pFontData->RemoveRef();
217 if (pFontData->use_count() > 1) 217 if (pFontData->use_count() != 0)
218 return; 218 return;
219 219
220 // We have font data only in m_FontMap cache. Clean it.
221 pFontData->clear(); 220 pFontData->clear();
222 } 221 }
223 222
224 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace( 223 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(
225 CPDF_Object* pCSObj, 224 CPDF_Object* pCSObj,
226 const CPDF_Dictionary* pResources) { 225 const CPDF_Dictionary* pResources) {
227 std::set<CPDF_Object*> visited; 226 std::set<CPDF_Object*> visited;
228 return GetColorSpaceImpl(pCSObj, pResources, &visited); 227 return GetColorSpaceImpl(pCSObj, pResources, &visited);
229 } 228 }
230 229
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 323
325 auto it = m_ColorSpaceMap.find(pColorSpace); 324 auto it = m_ColorSpaceMap.find(pColorSpace);
326 if (it == m_ColorSpaceMap.end()) 325 if (it == m_ColorSpaceMap.end())
327 return; 326 return;
328 327
329 CPDF_CountedColorSpace* pCountedColorSpace = it->second; 328 CPDF_CountedColorSpace* pCountedColorSpace = it->second;
330 if (!pCountedColorSpace->get()) 329 if (!pCountedColorSpace->get())
331 return; 330 return;
332 331
333 pCountedColorSpace->RemoveRef(); 332 pCountedColorSpace->RemoveRef();
334 if (pCountedColorSpace->use_count() > 1) 333 if (pCountedColorSpace->use_count() != 0)
335 return; 334 return;
336 335
337 // We have item only in m_ColorSpaceMap cache. Clean it.
338 pCountedColorSpace->get()->ReleaseCS(); 336 pCountedColorSpace->get()->ReleaseCS();
339 pCountedColorSpace->reset(nullptr); 337 pCountedColorSpace->reset(nullptr);
340 } 338 }
341 339
342 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, 340 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj,
343 FX_BOOL bShading, 341 FX_BOOL bShading,
344 const CFX_Matrix& matrix) { 342 const CFX_Matrix& matrix) {
345 if (!pPatternObj) 343 if (!pPatternObj)
346 return nullptr; 344 return nullptr;
347 345
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 384
387 auto it = m_PatternMap.find(pPatternObj); 385 auto it = m_PatternMap.find(pPatternObj);
388 if (it == m_PatternMap.end()) 386 if (it == m_PatternMap.end())
389 return; 387 return;
390 388
391 CPDF_CountedPattern* pPattern = it->second; 389 CPDF_CountedPattern* pPattern = it->second;
392 if (!pPattern->get()) 390 if (!pPattern->get())
393 return; 391 return;
394 392
395 pPattern->RemoveRef(); 393 pPattern->RemoveRef();
396 if (pPattern->use_count() > 1) 394 if (pPattern->use_count() != 0)
397 return; 395 return;
398 396
399 // We have item only in m_PatternMap cache. Clean it.
400 pPattern->clear(); 397 pPattern->clear();
401 } 398 }
402 399
403 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) { 400 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) {
404 if (!pImageStream) 401 if (!pImageStream)
405 return nullptr; 402 return nullptr;
406 403
407 const uint32_t dwImageObjNum = pImageStream->GetObjNum(); 404 const uint32_t dwImageObjNum = pImageStream->GetObjNum();
408 auto it = m_ImageMap.find(dwImageObjNum); 405 auto it = m_ImageMap.find(dwImageObjNum);
409 if (it != m_ImageMap.end()) 406 if (it != m_ImageMap.end())
(...skipping 15 matching lines...) Expand all
425 422
426 auto it = m_ImageMap.find(dwObjNum); 423 auto it = m_ImageMap.find(dwObjNum);
427 if (it == m_ImageMap.end()) 424 if (it == m_ImageMap.end())
428 return; 425 return;
429 426
430 CPDF_CountedImage* pCountedImage = it->second; 427 CPDF_CountedImage* pCountedImage = it->second;
431 if (!pCountedImage) 428 if (!pCountedImage)
432 return; 429 return;
433 430
434 pCountedImage->RemoveRef(); 431 pCountedImage->RemoveRef();
435 if (pCountedImage->use_count() > 1) 432 if (pCountedImage->use_count() != 0)
436 return; 433 return;
437 434
438 // We have item only in m_ImageMap cache. Clean it.
439 delete pCountedImage->get(); 435 delete pCountedImage->get();
440 delete pCountedImage; 436 delete pCountedImage;
441 m_ImageMap.erase(it); 437 m_ImageMap.erase(it);
442 } 438 }
443 439
444 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile( 440 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile(
445 CPDF_Stream* pIccProfileStream) { 441 CPDF_Stream* pIccProfileStream) {
446 if (!pIccProfileStream) 442 if (!pIccProfileStream)
447 return nullptr; 443 return nullptr;
448 444
449 auto it = m_IccProfileMap.find(pIccProfileStream); 445 auto it = m_IccProfileMap.find(pIccProfileStream);
450 if (it != m_IccProfileMap.end()) 446 if (it != m_IccProfileMap.end())
451 return it->second->AddRef(); 447 return it->second->AddRef();
452 448
453 CPDF_StreamAcc stream; 449 CPDF_StreamAcc stream;
454 stream.LoadAllData(pIccProfileStream, FALSE); 450 stream.LoadAllData(pIccProfileStream, FALSE);
455 uint8_t digest[20]; 451 uint8_t digest[20];
456 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); 452 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest);
457 CFX_ByteString bsDigest(digest, 20); 453 CFX_ByteString bsDigest(digest, 20);
458 auto hash_it = m_HashProfileMap.find(bsDigest); 454 auto hash_it = m_HashProfileMap.find(bsDigest);
459 if (hash_it != m_HashProfileMap.end()) { 455 if (hash_it != m_HashProfileMap.end()) {
460 auto it_copied_stream = m_IccProfileMap.find(hash_it->second); 456 auto it_copied_stream = m_IccProfileMap.find(hash_it->second);
461 if (it_copied_stream != m_IccProfileMap.end()) 457 return it_copied_stream->second->AddRef();
462 return it_copied_stream->second->AddRef();
463 } 458 }
464 CPDF_IccProfile* pProfile = 459 CPDF_IccProfile* pProfile =
465 new CPDF_IccProfile(stream.GetData(), stream.GetSize()); 460 new CPDF_IccProfile(stream.GetData(), stream.GetSize());
466 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); 461 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile);
467 m_IccProfileMap[pIccProfileStream] = ipData; 462 m_IccProfileMap[pIccProfileStream] = ipData;
468 m_HashProfileMap[bsDigest] = pIccProfileStream; 463 m_HashProfileMap[bsDigest] = pIccProfileStream;
469 return ipData->AddRef(); 464 return ipData->AddRef();
470 } 465 }
471 466
472 void CPDF_DocPageData::ReleaseIccProfile(const CPDF_IccProfile* pIccProfile) { 467 void CPDF_DocPageData::ReleaseIccProfile(const CPDF_IccProfile* pIccProfile) {
473 ASSERT(pIccProfile); 468 ASSERT(pIccProfile);
474 469
475 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) { 470 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) {
476 CPDF_CountedIccProfile* profile = it->second; 471 CPDF_CountedIccProfile* profile = it->second;
477 if (profile->get() != pIccProfile) 472 if (profile->get() != pIccProfile)
478 continue; 473 continue;
479 474
480 profile->RemoveRef(); 475 profile->RemoveRef();
481 if (profile->use_count() == 1) { 476 if (profile->use_count() == 0) {
482 // We have item only in m_IccProfileMap cache. Clean it.
483 delete profile->get(); 477 delete profile->get();
484 delete profile; 478 delete profile;
485 m_IccProfileMap.erase(it); 479 m_IccProfileMap.erase(it);
486 return; 480 return;
487 } 481 }
488 } 482 }
489 } 483 }
490 484
491 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc( 485 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(
492 CPDF_Stream* pFontStream) { 486 CPDF_Stream* pFontStream) {
(...skipping 24 matching lines...) Expand all
517 511
518 auto it = m_FontFileMap.find(pFontStream); 512 auto it = m_FontFileMap.find(pFontStream);
519 if (it == m_FontFileMap.end()) 513 if (it == m_FontFileMap.end())
520 return; 514 return;
521 515
522 CPDF_CountedStreamAcc* pCountedStream = it->second; 516 CPDF_CountedStreamAcc* pCountedStream = it->second;
523 if (!pCountedStream) 517 if (!pCountedStream)
524 return; 518 return;
525 519
526 pCountedStream->RemoveRef(); 520 pCountedStream->RemoveRef();
527 if (pCountedStream->use_count() > 1) 521 if (pCountedStream->use_count() != 0)
528 return; 522 return;
529 523
530 // We have item only in m_FontFileMap cache. Clean it.
531 delete pCountedStream->get(); 524 delete pCountedStream->get();
532 delete pCountedStream; 525 delete pCountedStream;
533 m_FontFileMap.erase(it); 526 m_FontFileMap.erase(it);
534 } 527 }
535 528
536 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr( 529 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(
537 CPDF_Object* pCSObj) const { 530 CPDF_Object* pCSObj) const {
538 if (!pCSObj) 531 if (!pCSObj)
539 return nullptr; 532 return nullptr;
540 533
541 auto it = m_ColorSpaceMap.find(pCSObj); 534 auto it = m_ColorSpaceMap.find(pCSObj);
542 return it != m_ColorSpaceMap.end() ? it->second : nullptr; 535 return it != m_ColorSpaceMap.end() ? it->second : nullptr;
543 } 536 }
544 537
545 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( 538 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(
546 CPDF_Object* pPatternObj) const { 539 CPDF_Object* pPatternObj) const {
547 if (!pPatternObj) 540 if (!pPatternObj)
548 return nullptr; 541 return nullptr;
549 542
550 auto it = m_PatternMap.find(pPatternObj); 543 auto it = m_PatternMap.find(pPatternObj);
551 return it != m_PatternMap.end() ? it->second : nullptr; 544 return it != m_PatternMap.end() ? it->second : nullptr;
552 } 545 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_parser/cpdf_document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698