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

Unified Diff: core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp

Issue 2355683002: Revert "Make CPDF_IndirectObjectHolder use unique_ptr to objects" (Closed)
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 side-by-side diff with in-line comments
Download patch
Index: core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
diff --git a/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp b/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
index 800e34b3d1eb62f3a1de4c4fc27c6a5727bc702a..dc639feb1a4b28915b5916d23e4fb68523e82c50 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
@@ -11,12 +11,15 @@
CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder() : m_LastObjNum(0) {}
-CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {}
+CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {
+ for (const auto& pair : m_IndirectObjs)
+ delete pair.second;
+}
CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(
uint32_t objnum) const {
auto it = m_IndirectObjs.find(objnum);
- return it != m_IndirectObjs.end() ? it->second.get() : nullptr;
+ return it != m_IndirectObjs.end() ? it->second : nullptr;
}
CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject(
@@ -34,7 +37,10 @@ CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject(
pObj->m_ObjNum = objnum;
m_LastObjNum = std::max(m_LastObjNum, objnum);
- m_IndirectObjs[objnum].reset(pObj);
+ if (m_IndirectObjs[objnum])
+ delete m_IndirectObjs[objnum];
+
+ m_IndirectObjs[objnum] = pObj;
return pObj;
}
@@ -47,7 +53,7 @@ uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) {
return pObj->m_ObjNum;
m_LastObjNum++;
- m_IndirectObjs[m_LastObjNum].reset(pObj);
+ m_IndirectObjs[m_LastObjNum] = pObj;
pObj->m_ObjNum = m_LastObjNum;
return m_LastObjNum;
}
@@ -59,12 +65,15 @@ bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration(
return false;
CPDF_Object* pOldObj = GetIndirectObject(objnum);
- if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) {
- delete pObj;
- return false;
+ if (pOldObj) {
+ if (pObj->GetGenNum() <= pOldObj->GetGenNum()) {
+ delete pObj;
+ return false;
+ }
+ delete pOldObj;
}
pObj->m_ObjNum = objnum;
- m_IndirectObjs[objnum].reset(pObj);
+ m_IndirectObjs[objnum] = pObj;
m_LastObjNum = std::max(m_LastObjNum, objnum);
return true;
}
@@ -74,5 +83,6 @@ void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) {
if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum)
return;
+ delete pObj;
m_IndirectObjs.erase(objnum);
}
« no previous file with comments | « core/fpdfapi/fpdf_parser/cfdf_document.cpp ('k') | core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698