summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_docpagedata.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-03 15:40:22 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 17:02:49 +0000
commit6088612c21898eb79cfbde401984176dd94c385c (patch)
tree4e9ad42317d7057b170f8f9cb6898bb30e63a481 /core/fpdfapi/page/cpdf_docpagedata.cpp
parent37cc5fb6b3407ce8e079bc1bdd0606713b975532 (diff)
downloadpdfium-6088612c21898eb79cfbde401984176dd94c385c.tar.xz
RefCount CPDF_IccProfile all the time
Make the IccProfile track its stream so that it has a proper key with which to purge the docpagedata map. Change-Id: Ib05ebc1afb828f1f5e5df62a1a33a1bfdecf507d Reviewed-on: https://pdfium-review.googlesource.com/3619 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/cpdf_docpagedata.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.cpp58
1 files changed, 21 insertions, 37 deletions
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index 5789a531f0..a57c42d3cd 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -82,11 +82,7 @@ void CPDF_DocPageData::Clear(bool bForceRelease) {
for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end();) {
auto curr_it = it++;
- CPDF_CountedIccProfile* ipData = curr_it->second;
- if (!ipData->get())
- continue;
-
- if (bForceRelease || ipData->use_count() < 2) {
+ if (bForceRelease || curr_it->second->HasOneRef()) {
for (auto hash_it = m_HashProfileMap.begin();
hash_it != m_HashProfileMap.end(); ++hash_it) {
if (curr_it->first == hash_it->second) {
@@ -94,8 +90,6 @@ void CPDF_DocPageData::Clear(bool bForceRelease) {
break;
}
}
- delete ipData->get();
- delete ipData;
m_IccProfileMap.erase(curr_it);
}
}
@@ -405,50 +399,40 @@ void CPDF_DocPageData::MaybePurgeImage(uint32_t dwStreamObjNum) {
m_ImageMap.erase(it);
}
-CPDF_IccProfile* CPDF_DocPageData::GetIccProfile(
- CPDF_Stream* pIccProfileStream) {
- if (!pIccProfileStream)
+CFX_RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
+ CPDF_Stream* pProfileStream) {
+ if (!pProfileStream)
return nullptr;
- auto it = m_IccProfileMap.find(pIccProfileStream);
+ auto it = m_IccProfileMap.find(pProfileStream);
if (it != m_IccProfileMap.end())
- return it->second->AddRef();
+ return it->second;
+
+ CPDF_StreamAcc accessor;
+ accessor.LoadAllData(pProfileStream, false);
- CPDF_StreamAcc stream;
- stream.LoadAllData(pIccProfileStream, false);
uint8_t digest[20];
- CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest);
+ CRYPT_SHA1Generate(accessor.GetData(), accessor.GetSize(), digest);
+
CFX_ByteString bsDigest(digest, 20);
auto hash_it = m_HashProfileMap.find(bsDigest);
if (hash_it != m_HashProfileMap.end()) {
auto it_copied_stream = m_IccProfileMap.find(hash_it->second);
if (it_copied_stream != m_IccProfileMap.end())
- return it_copied_stream->second->AddRef();
+ return it_copied_stream->second;
}
- CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(
- pdfium::MakeUnique<CPDF_IccProfile>(stream.GetData(), stream.GetSize()));
- m_IccProfileMap[pIccProfileStream] = ipData;
- m_HashProfileMap[bsDigest] = pIccProfileStream;
- return ipData->AddRef();
+ auto pProfile = pdfium::MakeRetain<CPDF_IccProfile>(
+ pProfileStream, accessor.GetData(), accessor.GetSize());
+ m_IccProfileMap[pProfileStream] = pProfile;
+ m_HashProfileMap[bsDigest] = pProfileStream;
+ return pProfile;
}
-void CPDF_DocPageData::ReleaseIccProfile(const CPDF_IccProfile* pIccProfile) {
- ASSERT(pIccProfile);
-
- for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) {
- CPDF_CountedIccProfile* profile = it->second;
- if (profile->get() != pIccProfile)
- continue;
-
- profile->RemoveRef();
- if (profile->use_count() > 1)
- continue;
- // We have item only in m_IccProfileMap cache. Clean it.
- delete profile->get();
- delete profile;
+void CPDF_DocPageData::MaybePurgeIccProfile(CPDF_Stream* pProfileStream) {
+ ASSERT(pProfileStream);
+ auto it = m_IccProfileMap.find(pProfileStream);
+ if (it != m_IccProfileMap.end() && it->second->HasOneRef())
m_IccProfileMap.erase(it);
- return;
- }
}
CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(