summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-09-21 14:04:25 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-21 14:04:25 -0700
commit298880f334ff1b8a1f3414d8ea8c2103e7755300 (patch)
tree19aa99e6c7835f24baad0c911b4637c3e6aa0a1d
parent17103b84ebde9ab2b05dff38d473b5d44f723ff2 (diff)
downloadpdfium-298880f334ff1b8a1f3414d8ea8c2103e7755300.tar.xz
Use unique_ptr<CPDF_Object, ReleaseDeleter<>> in more placeschromium/2868
Review-Url: https://codereview.chromium.org/2358243002
-rw-r--r--core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp15
-rw-r--r--core/fpdfapi/fpdf_edit/include/cpdf_creator.h2
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp9
3 files changed, 11 insertions, 15 deletions
diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
index c43306317a..d29b9834fa 100644
--- a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
+++ b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
@@ -814,7 +814,7 @@ FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator,
offset += len + 8;
if (bEOF) {
if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile,
- pCreator->m_pIDArray)) < 0) {
+ pCreator->m_pIDArray.get())) < 0) {
return FALSE;
}
offset += len;
@@ -1810,7 +1810,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) {
return -1;
}
FX_FILESIZE offset = 0;
- if (PDF_CreatorAppendObject(m_pIDArray, &m_File, offset) < 0) {
+ if (PDF_CreatorAppendObject(m_pIDArray.get(), &m_File, offset) < 0) {
return -1;
}
}
@@ -1904,10 +1904,7 @@ void CPDF_Creator::Clear() {
m_pXRefStream.reset();
m_File.Clear();
m_NewObjNumArray.RemoveAll();
- if (m_pIDArray) {
- m_pIDArray->Release();
- m_pIDArray = nullptr;
- }
+ m_pIDArray.reset();
}
bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) {
@@ -1931,8 +1928,8 @@ bool CPDF_Creator::Create(uint32_t flags) {
void CPDF_Creator::InitID(FX_BOOL bDefault) {
CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr;
FX_BOOL bNewId = !m_pIDArray;
- if (!m_pIDArray) {
- m_pIDArray = new CPDF_Array;
+ if (bNewId) {
+ m_pIDArray.reset(new CPDF_Array);
CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr;
if (pID1) {
m_pIDArray->Add(pID1->Clone());
@@ -1965,7 +1962,7 @@ void CPDF_Creator::InitID(FX_BOOL bDefault) {
uint32_t flag = PDF_ENCRYPT_CONTENT;
CPDF_SecurityHandler handler;
- handler.OnCreate(m_pEncryptDict, m_pIDArray, user_pass.raw_str(),
+ handler.OnCreate(m_pEncryptDict, m_pIDArray.get(), user_pass.raw_str(),
user_pass.GetLength(), flag);
if (m_bLocalCryptoHandler)
delete m_pCryptoHandler;
diff --git a/core/fpdfapi/fpdf_edit/include/cpdf_creator.h b/core/fpdfapi/fpdf_edit/include/cpdf_creator.h
index 285efff4b0..d922e216ff 100644
--- a/core/fpdfapi/fpdf_edit/include/cpdf_creator.h
+++ b/core/fpdfapi/fpdf_edit/include/cpdf_creator.h
@@ -94,7 +94,7 @@ class CPDF_Creator {
FX_FILESIZE m_XrefStart;
CFX_FileSizeListArray m_ObjectOffset;
CFX_ArrayTemplate<uint32_t> m_NewObjNumArray;
- CPDF_Array* m_pIDArray;
+ std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> m_pIDArray;
int32_t m_FileVersion;
};
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index cbce1aaf69..38f7648e0b 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -577,17 +577,16 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
if (pValue->GetUnicodeText() == opt_value)
m_pDict->RemoveFor("V");
} else if (pValue->IsArray()) {
- CPDF_Array* pArray = new CPDF_Array;
+ std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray(
+ new CPDF_Array);
for (int i = 0; i < CountOptions(); i++) {
if (i != index && IsItemSelected(i)) {
opt_value = GetOptionValue(i);
pArray->AddString(PDF_EncodeText(opt_value));
}
}
- if (pArray->GetCount() < 1)
- pArray->Release();
- else
- m_pDict->SetFor("V", pArray);
+ if (pArray->GetCount() > 0)
+ m_pDict->SetFor("V", pArray.release()); // std::move someday
}
} else {
m_pDict->RemoveFor("V");