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

Unified Diff: fpdfsdk/fpdfppo.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: Plug leaks Created 4 years, 1 month 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: fpdfsdk/fpdfppo.cpp
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index 915de1ad0730f8726865dbc031c0d55f4912a2f2..aea637704936ec142fb015bed2b5320380925a88 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -64,7 +64,7 @@ bool CopyInheritable(CPDF_Dictionary* pCurPageDict,
if (!pInheritable)
return false;
- pCurPageDict->SetFor(key, pInheritable->Clone().release());
+ pCurPageDict->SetFor(key, pInheritable->Clone());
return true;
}
@@ -158,31 +158,30 @@ bool CPDF_PageOrganizer::PDFDocInit() {
if (!pDocInfoDict)
return false;
- CFX_ByteString producerstr;
- producerstr.Format("PDFium");
- pDocInfoDict->SetFor("Producer",
- new CPDF_String(nullptr, producerstr, false));
+ pDocInfoDict->SetNewFor<CPDF_String>("Producer", "PDFium", false);
CFX_ByteString cbRootType = pNewRoot->GetStringFor("Type", "");
if (cbRootType.IsEmpty())
- pNewRoot->SetFor("Type", new CPDF_Name(nullptr, "Catalog"));
+ pNewRoot->SetNewFor<CPDF_Name>("Type", "Catalog");
CPDF_Object* pElement = pNewRoot->GetObjectFor("Pages");
CPDF_Dictionary* pNewPages =
pElement ? ToDictionary(pElement->GetDirect()) : nullptr;
if (!pNewPages) {
pNewPages = m_pDestPDFDoc->NewIndirect<CPDF_Dictionary>();
- pNewRoot->SetReferenceFor("Pages", m_pDestPDFDoc, pNewPages);
+ pNewRoot->SetNewFor<CPDF_Reference>("Pages", m_pDestPDFDoc,
+ pNewPages->GetObjNum());
}
CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", "");
if (cbPageType.IsEmpty())
- pNewPages->SetFor("Type", new CPDF_Name(nullptr, "Pages"));
+ pNewPages->SetNewFor<CPDF_Name>("Type", "Pages");
if (!pNewPages->GetArrayFor("Kids")) {
- pNewPages->SetIntegerFor("Count", 0);
- pNewPages->SetReferenceFor("Kids", m_pDestPDFDoc,
- m_pDestPDFDoc->NewIndirect<CPDF_Array>());
+ pNewPages->SetNewFor<CPDF_Number>("Count", 0);
+ pNewPages->SetNewFor<CPDF_Reference>(
+ "Kids", m_pDestPDFDoc,
+ m_pDestPDFDoc->NewIndirect<CPDF_Array>()->GetObjNum());
}
return true;
@@ -202,11 +201,11 @@ bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums,
// Clone the page dictionary
for (const auto& it : *pSrcPageDict) {
const CFX_ByteString& cbSrcKeyStr = it.first;
- CPDF_Object* pObj = it.second;
if (cbSrcKeyStr == "Type" || cbSrcKeyStr == "Parent")
continue;
- pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone().release());
+ CPDF_Object* pObj = it.second.get();
+ pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone());
}
// inheritable item
@@ -217,15 +216,14 @@ bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums,
CPDF_Object* pInheritable =
PageDictGetInheritableTag(pSrcPageDict, "CropBox");
if (pInheritable) {
- pCurPageDict->SetFor("MediaBox", pInheritable->Clone().release());
+ pCurPageDict->SetFor("MediaBox", pInheritable->Clone());
} else {
// Make the default size to be letter size (8.5'x11')
- CPDF_Array* pArray = new CPDF_Array;
+ CPDF_Array* pArray = pCurPageDict->SetNewFor<CPDF_Array>("MediaBox");
pArray->AddNew<CPDF_Number>(0);
pArray->AddNew<CPDF_Number>(0);
pArray->AddNew<CPDF_Number>(612);
pArray->AddNew<CPDF_Number>(792);
- pCurPageDict->SetFor("MediaBox", pArray);
}
}
@@ -265,7 +263,7 @@ bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
auto it = pDict->begin();
while (it != pDict->end()) {
const CFX_ByteString& key = it->first;
- CPDF_Object* pNextObj = it->second;
+ CPDF_Object* pNextObj = it->second.get();
++it;
if (key == "Parent" || key == "Prev" || key == "First")
continue;
@@ -386,7 +384,6 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc,
if (!pDstDict)
return false;
- pDstDict->SetFor("ViewerPreferences",
- pSrcDict->CloneDirectObject().release());
+ pDstDict->SetFor("ViewerPreferences", pSrcDict->CloneDirectObject());
return true;
}

Powered by Google App Engine
This is Rietveld 408576698