diff options
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cfdf_document.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_array.cpp | 13 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_array.h | 8 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_array_unittest.cpp | 26 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 61 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_dictionary.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_dictionary.h | 11 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document_unittest.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_indirect_object_holder.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_indirect_object_holder.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_object.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_object.h | 8 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_object_unittest.cpp | 76 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_parser.cpp | 54 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_stream.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_stream.h | 10 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_string.h | 3 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_syntax_parser.cpp | 17 |
19 files changed, 130 insertions, 185 deletions
diff --git a/core/fpdfapi/parser/cfdf_document.cpp b/core/fpdfapi/parser/cfdf_document.cpp index bcaa9daec3..e66bfeb12b 100644 --- a/core/fpdfapi/parser/cfdf_document.cpp +++ b/core/fpdfapi/parser/cfdf_document.cpp @@ -84,7 +84,7 @@ void CFDF_Document::ParseStream(IFX_SeekableReadStream* pFile, bool bOwnFile) { if (CPDF_Dictionary* pMainDict = ToDictionary(parser.GetObject(this, 0, 0, true))) { m_pRootDict = pMainDict->GetDictFor("Root"); - pMainDict->Release(); + delete pMainDict; } break; } diff --git a/core/fpdfapi/parser/cpdf_array.cpp b/core/fpdfapi/parser/cpdf_array.cpp index e118fd66e6..4000bbc980 100644 --- a/core/fpdfapi/parser/cpdf_array.cpp +++ b/core/fpdfapi/parser/cpdf_array.cpp @@ -24,7 +24,7 @@ CPDF_Array::~CPDF_Array() { m_ObjNum = kInvalidObjNum; for (auto& it : m_Objects) { if (it && it->GetObjNum() != kInvalidObjNum) - it->Release(); + delete it; } } @@ -139,10 +139,9 @@ void CPDF_Array::RemoveAt(size_t i, size_t nCount) { if (nCount <= 0 || nCount > m_Objects.size() - i) return; - for (size_t j = 0; j < nCount; ++j) { - if (CPDF_Object* p = m_Objects[i + j]) - p->Release(); - } + for (size_t j = 0; j < nCount; ++j) + delete m_Objects[i + j]; + m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount); } @@ -166,9 +165,7 @@ void CPDF_Array::SetAt(size_t i, CPDF_Object* pObj) { ASSERT(false); return; } - if (CPDF_Object* pOld = m_Objects[i]) - pOld->Release(); - + delete m_Objects[i]; m_Objects[i] = pObj; } diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h index 8cfa0333bb..9deb478809 100644 --- a/core/fpdfapi/parser/cpdf_array.h +++ b/core/fpdfapi/parser/cpdf_array.h @@ -21,6 +21,7 @@ class CPDF_Array : public CPDF_Object { using const_iterator = std::vector<CPDF_Object*>::const_iterator; CPDF_Array(); + ~CPDF_Array() override; // CPDF_Object. Type GetType() const override; @@ -61,15 +62,12 @@ class CPDF_Array : public CPDF_Object { const_iterator end() const { return m_Objects.end(); } protected: - ~CPDF_Array() override; - CPDF_Object* CloneNonCyclic( bool bDirect, std::set<const CPDF_Object*>* pVisited) const override; std::vector<CPDF_Object*> m_Objects; }; -using UniqueArray = std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Object>>; inline CPDF_Array* ToArray(CPDF_Object* obj) { return obj ? obj->AsArray() : nullptr; @@ -79,12 +77,12 @@ inline const CPDF_Array* ToArray(const CPDF_Object* obj) { return obj ? obj->AsArray() : nullptr; } -inline UniqueArray ToArray(UniqueObject obj) { +inline std::unique_ptr<CPDF_Array> ToArray(std::unique_ptr<CPDF_Object> obj) { CPDF_Array* pArray = ToArray(obj.get()); if (!pArray) return nullptr; obj.release(); - return UniqueArray(pArray); + return std::unique_ptr<CPDF_Array>(pArray); } #endif // CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_ diff --git a/core/fpdfapi/parser/cpdf_array_unittest.cpp b/core/fpdfapi/parser/cpdf_array_unittest.cpp index bc9f578021..800afb0f9a 100644 --- a/core/fpdfapi/parser/cpdf_array_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_array_unittest.cpp @@ -10,16 +10,10 @@ #include "testing/gtest/include/gtest/gtest.h" -namespace { - -using ScopedArray = std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>>; - -} // namespace - TEST(cpdf_array, RemoveAt) { { int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->AddInteger(elems[i]); arr->RemoveAt(3, 3); @@ -36,7 +30,7 @@ TEST(cpdf_array, RemoveAt) { { // When the range is out of bound, RemoveAt has no effect. int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->AddInteger(elems[i]); arr->RemoveAt(8, 5); @@ -53,7 +47,7 @@ TEST(cpdf_array, RemoveAt) { TEST(cpdf_array, InsertAt) { { int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->InsertAt(i, new CPDF_Number(elems[i])); EXPECT_EQ(FX_ArraySize(elems), arr->GetCount()); @@ -72,7 +66,7 @@ TEST(cpdf_array, InsertAt) { // an element is inserted at that position while other unfilled // positions have nullptr. int elems[] = {1, 2}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->InsertAt(i, new CPDF_Number(elems[i])); arr->InsertAt(10, new CPDF_Number(10)); @@ -89,10 +83,10 @@ TEST(cpdf_array, Clone) { { // Basic case. int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->InsertAt(i, new CPDF_Number(elems[i])); - ScopedArray arr2(arr->Clone()->AsArray()); + std::unique_ptr<CPDF_Array> arr2(arr->Clone()->AsArray()); EXPECT_EQ(arr->GetCount(), arr2->GetCount()); for (size_t i = 0; i < FX_ArraySize(elems); ++i) { // Clone() always create new objects. @@ -106,7 +100,7 @@ TEST(cpdf_array, Clone) { static const size_t kNumOfRowElems = 5; int elems[kNumOfRows][kNumOfRowElems] = { {1, 2, 3, 4, 5}, {10, 9, 8, 7, 6}, {11, 12, 13, 14, 15}}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); // Indirect references to indirect objects. std::unique_ptr<CPDF_IndirectObjectHolder> obj_holder( new CPDF_IndirectObjectHolder()); @@ -124,10 +118,10 @@ TEST(cpdf_array, Clone) { ASSERT_EQ(kNumOfRows, arr->GetCount()); // Not dereferencing reference objects means just creating new references // instead of new copies of direct objects. - ScopedArray arr1(arr->Clone()->AsArray()); + std::unique_ptr<CPDF_Array> arr1(arr->Clone()->AsArray()); EXPECT_EQ(arr->GetCount(), arr1->GetCount()); // Dereferencing reference objects creates new copies of direct objects. - ScopedArray arr2(arr->CloneDirectObject()->AsArray()); + std::unique_ptr<CPDF_Array> arr2(arr->CloneDirectObject()->AsArray()); EXPECT_EQ(arr->GetCount(), arr2->GetCount()); for (size_t i = 0; i < kNumOfRows; ++i) { CPDF_Array* arr_elem = arr->GetObjectAt(i)->AsArray(); @@ -171,7 +165,7 @@ TEST(cpdf_array, Clone) { TEST(cpdf_array, Iterator) { int elems[] = {-23, -11, 3, 455, 2345877, 0, 7895330, -12564334, 10000, -100000}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->InsertAt(i, new CPDF_Number(elems[i])); size_t index = 0; diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index a077ebb715..eadbf1e828 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -83,17 +83,12 @@ CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, CPDF_DataAvail::~CPDF_DataAvail() { m_pHintTables.reset(); - if (m_pLinearized) - m_pLinearized->Release(); - - if (m_pRoot) - m_pRoot->Release(); - - if (m_pTrailer) - m_pTrailer->Release(); + delete m_pLinearized; + delete m_pRoot; + delete m_pTrailer; for (CPDF_Object* pObject : m_arrayAcroforms) - pObject->Release(); + delete pObject; } void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { @@ -230,7 +225,7 @@ bool CPDF_DataAvail::CheckAcroFormSubObject(DownloadHints* pHints) { } for (CPDF_Object* pObject : m_arrayAcroforms) - pObject->Release(); + delete pObject; m_arrayAcroforms.clear(); return true; @@ -400,9 +395,7 @@ bool CPDF_DataAvail::CheckInfo(DownloadHints* pHints) { return false; } - if (pInfo) - pInfo->Release(); - + delete pInfo; m_docStatus = (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); @@ -499,7 +492,7 @@ bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) { } if (!pObj->IsDictionary()) { - pObj->Release(); + delete pObj; continue; } @@ -508,7 +501,7 @@ bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) { m_PagesArray.push_back(pObj); continue; } - pObj->Release(); + delete pObj; } m_PageObjList.RemoveAll(); @@ -524,15 +517,15 @@ bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) { continue; if (!GetPageKids(m_pCurrentParser, pPages)) { - pPages->Release(); + delete pPages; while (++i < iPages) - m_PagesArray[i]->Release(); + delete m_PagesArray[i]; m_PagesArray.clear(); m_docStatus = PDF_DATAAVAIL_ERROR; return false; } - pPages->Release(); + delete pPages; } m_PagesArray.clear(); @@ -587,12 +580,12 @@ bool CPDF_DataAvail::CheckPages(DownloadHints* pHints) { } if (!GetPageKids(m_pCurrentParser, pPages)) { - pPages->Release(); + delete pPages; m_docStatus = PDF_DATAAVAIL_ERROR; return false; } - pPages->Release(); + delete pPages; m_docStatus = PDF_DATAAVAIL_PAGE; return true; } @@ -763,7 +756,7 @@ bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { std::unique_ptr<CPDF_HintTables> pHintTables( new CPDF_HintTables(this, pDict)); - std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream( + std::unique_ptr<CPDF_Object> pHintStream( ParseIndirectObjectAt(szHintStart, 0)); CPDF_Stream* pStream = ToStream(pHintStream.get()); if (pStream && pHintTables->LoadHintStream(pStream)) @@ -951,11 +944,11 @@ int32_t CPDF_DataAvail::CheckCrossRefStream(DownloadHints* pHints, if (pName->GetString() == "XRef") { m_Pos += m_parser.m_pSyntax->SavePos(); xref_offset = pObj->GetDict()->GetIntegerFor("Prev"); - pObj->Release(); + delete pObj; return 1; } } - pObj->Release(); + delete pObj; return -1; } pHints->AddSegment(m_Pos, req_size); @@ -1181,7 +1174,7 @@ bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, false)); m_syntaxParser.InitParser(file.get(), 0); - std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pTrailer( + std::unique_ptr<CPDF_Object> pTrailer( m_syntaxParser.GetObject(nullptr, 0, 0, true)); if (!pTrailer) { m_Pos += m_syntaxParser.SavePos(); @@ -1266,7 +1259,7 @@ bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo, CPDF_Array* pArray = pPages->AsArray(); if (!pArray) { - pPages->Release(); + delete pPages; m_docStatus = PDF_DATAAVAIL_ERROR; return false; } @@ -1281,7 +1274,7 @@ bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo, pPageNode->m_childNode.Add(pNode); pNode->m_dwPageNo = pKid->GetRefObjNum(); } - pPages->Release(); + delete pPages; return true; } @@ -1304,12 +1297,12 @@ bool CPDF_DataAvail::CheckUnkownPageNode(uint32_t dwPageNo, if (pPage->IsArray()) { pPageNode->m_dwPageNo = dwPageNo; pPageNode->m_type = PDF_PAGENODE_ARRAY; - pPage->Release(); + delete pPage; return true; } if (!pPage->IsDictionary()) { - pPage->Release(); + delete pPage; m_docStatus = PDF_DATAAVAIL_ERROR; return false; } @@ -1350,11 +1343,11 @@ bool CPDF_DataAvail::CheckUnkownPageNode(uint32_t dwPageNo, } else if (type == "Page") { pPageNode->m_type = PDF_PAGENODE_PAGE; } else { - pPage->Release(); + delete pPage; m_docStatus = PDF_DATAAVAIL_ERROR; return false; } - pPage->Release(); + delete pPage; return true; } @@ -1442,23 +1435,23 @@ bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) { CPDF_Dictionary* pPagesDict = pPages->GetDict(); if (!pPagesDict) { - pPages->Release(); + delete pPages; m_docStatus = PDF_DATAAVAIL_ERROR; return false; } if (!pPagesDict->KeyExist("Kids")) { - pPages->Release(); + delete pPages; return true; } int count = pPagesDict->GetIntegerFor("Count"); if (count > 0) { - pPages->Release(); + delete pPages; return true; } - pPages->Release(); + delete pPages; return false; } diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp index 75cb1e859c..37efbbc34a 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/parser/cpdf_dictionary.cpp @@ -31,7 +31,7 @@ CPDF_Dictionary::~CPDF_Dictionary() { m_ObjNum = kInvalidObjNum; for (const auto& it : m_Map) { if (it.second && it.second->GetObjNum() != kInvalidObjNum) - it.second->Release(); + delete it.second; } } @@ -184,7 +184,7 @@ void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) { if (it->second == pObj) return; - it->second->Release(); + delete it->second; if (pObj) it->second = pObj; @@ -208,7 +208,7 @@ void CPDF_Dictionary::RemoveFor(const CFX_ByteString& key) { if (it == m_Map.end()) return; - it->second->Release(); + delete it->second; m_Map.erase(it); } @@ -223,7 +223,7 @@ void CPDF_Dictionary::ReplaceKey(const CFX_ByteString& oldkey, return; if (new_it != m_Map.end()) { - new_it->second->Release(); + delete new_it->second; new_it->second = old_it->second; } else { m_Map.insert(std::make_pair(MaybeIntern(newkey), old_it->second)); diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h index fb8200f78c..4ef2f96ce7 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.h +++ b/core/fpdfapi/parser/cpdf_dictionary.h @@ -26,6 +26,7 @@ class CPDF_Dictionary : public CPDF_Object { CPDF_Dictionary(); explicit CPDF_Dictionary(const CFX_WeakPtr<CFX_ByteStringPool>& pPool); + ~CPDF_Dictionary() override; // CPDF_Object. Type GetType() const override; @@ -88,8 +89,6 @@ class CPDF_Dictionary : public CPDF_Object { CFX_WeakPtr<CFX_ByteStringPool> GetByteStringPool() const { return m_pPool; } protected: - ~CPDF_Dictionary() override; - CFX_ByteString MaybeIntern(const CFX_ByteString& str); CPDF_Object* CloneNonCyclic( bool bDirect, @@ -99,9 +98,6 @@ class CPDF_Dictionary : public CPDF_Object { std::map<CFX_ByteString, CPDF_Object*> m_Map; }; -using UniqueDictionary = - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Object>>; - inline CPDF_Dictionary* ToDictionary(CPDF_Object* obj) { return obj ? obj->AsDictionary() : nullptr; } @@ -110,12 +106,13 @@ inline const CPDF_Dictionary* ToDictionary(const CPDF_Object* obj) { return obj ? obj->AsDictionary() : nullptr; } -inline UniqueDictionary ToDictionary(UniqueObject obj) { +inline std::unique_ptr<CPDF_Dictionary> ToDictionary( + std::unique_ptr<CPDF_Object> obj) { CPDF_Dictionary* pDict = ToDictionary(obj.get()); if (!pDict) return nullptr; obj.release(); - return UniqueDictionary(pDict); + return std::unique_ptr<CPDF_Dictionary>(pDict); } #endif // CORE_FPDFAPI_PARSER_CPDF_DICTIONARY_H_ diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index ad84a15a97..64574047e5 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -634,7 +634,7 @@ CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { pDict->SetNameFor("Type", "Page"); uint32_t dwObjNum = AddIndirectObject(pDict); if (!InsertNewPage(iPage, pDict)) { - ReleaseIndirectObject(dwObjNum); + DeleteIndirectObject(dwObjNum); return nullptr; } return pDict; diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp index 9336626f45..c09665b716 100644 --- a/core/fpdfapi/parser/cpdf_document_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp @@ -76,8 +76,7 @@ class CPDF_TestDocumentForPages : public CPDF_Document { } private: - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> - m_pOwnedRootDict; + std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict; }; } // namespace @@ -121,7 +120,7 @@ TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { // can be not exists in this case. // (case, when hint table is used to page check in CPDF_DataAvail). CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); - ScopedDictionary dict(new CPDF_Dictionary()); + std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary()); const int page_count = 100; dict->SetIntegerFor("N", page_count); document.LoadLinearizedDoc(dict.get()); diff --git a/core/fpdfapi/parser/cpdf_indirect_object_holder.cpp b/core/fpdfapi/parser/cpdf_indirect_object_holder.cpp index 9427543396..d3204e04e5 100644 --- a/core/fpdfapi/parser/cpdf_indirect_object_holder.cpp +++ b/core/fpdfapi/parser/cpdf_indirect_object_holder.cpp @@ -71,7 +71,7 @@ bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( return true; } -void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { +void CPDF_IndirectObjectHolder::DeleteIndirectObject(uint32_t objnum) { CPDF_Object* pObj = GetIndirectObject(objnum); if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) return; diff --git a/core/fpdfapi/parser/cpdf_indirect_object_holder.h b/core/fpdfapi/parser/cpdf_indirect_object_holder.h index da4e942b5d..83a31535c4 100644 --- a/core/fpdfapi/parser/cpdf_indirect_object_holder.h +++ b/core/fpdfapi/parser/cpdf_indirect_object_holder.h @@ -24,7 +24,7 @@ class CPDF_IndirectObjectHolder { CPDF_Object* GetIndirectObject(uint32_t objnum) const; CPDF_Object* GetOrParseIndirectObject(uint32_t objnum); - void ReleaseIndirectObject(uint32_t objnum); + void DeleteIndirectObject(uint32_t objnum); // Take ownership of |pObj|. uint32_t AddIndirectObject(CPDF_Object* pObj); diff --git a/core/fpdfapi/parser/cpdf_object.cpp b/core/fpdfapi/parser/cpdf_object.cpp index cc410d10c8..e9c215ce19 100644 --- a/core/fpdfapi/parser/cpdf_object.cpp +++ b/core/fpdfapi/parser/cpdf_object.cpp @@ -37,11 +37,6 @@ CPDF_Object* CPDF_Object::CloneNonCyclic( return Clone(); } -void CPDF_Object::Release() { - CHECK(!m_ObjNum); - delete this; -} - CFX_ByteString CPDF_Object::GetString() const { return CFX_ByteString(); } diff --git a/core/fpdfapi/parser/cpdf_object.h b/core/fpdfapi/parser/cpdf_object.h index c888605d72..8f6491ec72 100644 --- a/core/fpdfapi/parser/cpdf_object.h +++ b/core/fpdfapi/parser/cpdf_object.h @@ -38,6 +38,8 @@ class CPDF_Object { REFERENCE }; + virtual ~CPDF_Object(); + virtual Type GetType() const = 0; uint32_t GetObjNum() const { return m_ObjNum; } uint32_t GetGenNum() const { return m_GenNum; } @@ -50,8 +52,6 @@ class CPDF_Object { virtual CPDF_Object* CloneDirectObject() const; virtual CPDF_Object* GetDirect() const; - void Release(); - virtual CFX_ByteString GetString() const; virtual CFX_WideString GetUnicodeText() const; virtual FX_FLOAT GetNumber() const; @@ -94,10 +94,8 @@ class CPDF_Object { friend class CPDF_Parser; friend class CPDF_Reference; friend class CPDF_Stream; - friend struct std::default_delete<CPDF_Object>; CPDF_Object() : m_ObjNum(0), m_GenNum(0) {} - virtual ~CPDF_Object(); CPDF_Object* CloneObjectNonCyclic(bool bDirect) const; @@ -118,6 +116,4 @@ class CPDF_Object { CPDF_Object(const CPDF_Object& src) {} }; -using UniqueObject = std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>>; - #endif // CORE_FPDFAPI_PARSER_CPDF_OBJECT_H_ diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp index 8215226ef3..64dc8c63ec 100644 --- a/core/fpdfapi/parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp @@ -22,11 +22,6 @@ namespace { -using ScopedArray = std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>>; -using ScopedDict = - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>; -using ScopedStream = std::unique_ptr<CPDF_Stream, ReleaseDeleter<CPDF_Stream>>; - void TestArrayAccessors(const CPDF_Array* arr, size_t index, const char* str_val, @@ -173,14 +168,12 @@ class PDFObjectsTest : public testing::Test { } protected: - using ScopedObj = std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>>; - // m_ObjHolder needs to be declared first and destructed last since it also // refers to some objects in m_DirectObjs. std::unique_ptr<CPDF_IndirectObjectHolder> m_ObjHolder; - std::vector<ScopedObj> m_DirectObjs; + std::vector<std::unique_ptr<CPDF_Object>> m_DirectObjs; std::vector<int> m_DirectObjTypes; - std::vector<ScopedObj> m_RefObjs; + std::vector<std::unique_ptr<CPDF_Object>> m_RefObjs; CPDF_Dictionary* m_DictObj; CPDF_Dictionary* m_StreamDictObj; CPDF_Array* m_ArrayObj; @@ -275,13 +268,13 @@ TEST_F(PDFObjectsTest, GetArray) { TEST_F(PDFObjectsTest, Clone) { // Check for direct objects. for (size_t i = 0; i < m_DirectObjs.size(); ++i) { - ScopedObj obj(m_DirectObjs[i]->Clone()); + std::unique_ptr<CPDF_Object> obj(m_DirectObjs[i]->Clone()); EXPECT_TRUE(Equal(m_DirectObjs[i].get(), obj.get())); } // Check indirect references. for (const auto& it : m_RefObjs) { - ScopedObj obj(it->Clone()); + std::unique_ptr<CPDF_Object> obj(it->Clone()); EXPECT_TRUE(Equal(it.get(), obj.get())); } } @@ -393,7 +386,7 @@ TEST(PDFArrayTest, GetMatrix) { {2.3f, 4.05f, 3, -2, -3, 0.0f}, {0.05f, 0.1f, 0.56f, 0.67f, 1.34f, 99.9f}}; for (size_t i = 0; i < FX_ArraySize(elems); ++i) { - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); CFX_Matrix matrix(elems[i][0], elems[i][1], elems[i][2], elems[i][3], elems[i][4], elems[i][5]); for (size_t j = 0; j < 6; ++j) @@ -414,7 +407,7 @@ TEST(PDFArrayTest, GetRect) { {2.3f, 4.05f, -3, 0.0f}, {0.05f, 0.1f, 1.34f, 99.9f}}; for (size_t i = 0; i < FX_ArraySize(elems); ++i) { - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); CFX_FloatRect rect(elems[i]); for (size_t j = 0; j < 4; ++j) arr->AddNumber(elems[i][j]); @@ -430,7 +423,7 @@ TEST(PDFArrayTest, GetTypeAt) { { // Boolean array. const bool vals[] = {true, false, false, true, true}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(vals); ++i) arr->InsertAt(i, new CPDF_Boolean(vals[i])); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { @@ -447,7 +440,7 @@ TEST(PDFArrayTest, GetTypeAt) { { // Integer array. const int vals[] = {10, 0, -345, 2089345456, -1000000000, 567, 93658767}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(vals); ++i) arr->InsertAt(i, new CPDF_Number(vals[i])); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { @@ -468,7 +461,7 @@ TEST(PDFArrayTest, GetTypeAt) { 897.34f, -2.5f, -1.0f, -345.0f, -0.0f}; const char* const expected_str[] = { "0", "0", "10", "10", "0.0345", "897.34", "-2.5", "-1", "-345", "0"}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { arr->InsertAt(i, new CPDF_Number(vals[i])); } @@ -487,8 +480,8 @@ TEST(PDFArrayTest, GetTypeAt) { // String and name array const char* const vals[] = {"this", "adsde$%^", "\r\t", "\"012", ".", "EYREW", "It is a joke :)"}; - ScopedArray string_array(new CPDF_Array); - ScopedArray name_array(new CPDF_Array); + std::unique_ptr<CPDF_Array> string_array(new CPDF_Array); + std::unique_ptr<CPDF_Array> name_array(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { string_array->InsertAt(i, new CPDF_String(vals[i], false)); name_array->InsertAt(i, new CPDF_Name(vals[i])); @@ -514,7 +507,7 @@ TEST(PDFArrayTest, GetTypeAt) { } { // Null element array. - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < 3; ++i) arr->InsertAt(i, new CPDF_Null); for (size_t i = 0; i < 3; ++i) { @@ -531,7 +524,7 @@ TEST(PDFArrayTest, GetTypeAt) { { // Array of array. CPDF_Array* vals[3]; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < 3; ++i) { vals[i] = new CPDF_Array; for (size_t j = 0; j < 3; ++j) { @@ -554,7 +547,7 @@ TEST(PDFArrayTest, GetTypeAt) { { // Dictionary array. CPDF_Dictionary* vals[3]; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < 3; ++i) { vals[i] = new CPDF_Dictionary(); for (size_t j = 0; j < 3; ++j) { @@ -581,7 +574,7 @@ TEST(PDFArrayTest, GetTypeAt) { // Stream array. CPDF_Dictionary* vals[3]; CPDF_Stream* stream_vals[3]; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < 3; ++i) { vals[i] = new CPDF_Dictionary(); for (size_t j = 0; j < 3; ++j) { @@ -611,7 +604,7 @@ TEST(PDFArrayTest, GetTypeAt) { } { // Mixed array. - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); // Array arr will take ownership of all the objects inserted. arr->InsertAt(0, new CPDF_Boolean(true)); arr->InsertAt(1, new CPDF_Boolean(false)); @@ -676,7 +669,7 @@ TEST(PDFArrayTest, GetTypeAt) { TEST(PDFArrayTest, AddNumber) { float vals[] = {1.0f, -1.0f, 0, 0.456734f, 12345.54321f, 0.5f, 1000, 0.000045f}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(vals); ++i) arr->AddNumber(vals[i]); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { @@ -687,7 +680,7 @@ TEST(PDFArrayTest, AddNumber) { TEST(PDFArrayTest, AddInteger) { int vals[] = {0, 1, 934435456, 876, 10000, -1, -24354656, -100}; - ScopedArray arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(vals); ++i) arr->AddInteger(vals[i]); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { @@ -699,8 +692,8 @@ TEST(PDFArrayTest, AddInteger) { TEST(PDFArrayTest, AddStringAndName) { const char* vals[] = {"", "a", "ehjhRIOYTTFdfcdnv", "122323", "$#%^&**", " ", "This is a test.\r\n"}; - ScopedArray string_array(new CPDF_Array); - ScopedArray name_array(new CPDF_Array); + std::unique_ptr<CPDF_Array> string_array(new CPDF_Array); + std::unique_ptr<CPDF_Array> name_array(new CPDF_Array); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { string_array->AddString(vals[i]); name_array->AddName(vals[i]); @@ -725,8 +718,8 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj, str_obj, name_obj, null_obj}; unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1}; - ScopedArray arr(new CPDF_Array); - ScopedArray arr1(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr1(new CPDF_Array); // Create two arrays of references by different AddReference() APIs. for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) { // All the indirect objects inserted will be owned by holder. @@ -752,7 +745,7 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { TEST(PDFArrayTest, CloneDirectObject) { CPDF_IndirectObjectHolder objects_holder; - ScopedArray array(new CPDF_Array); + std::unique_ptr<CPDF_Array> array(new CPDF_Array); array->AddReference(&objects_holder, 1234); ASSERT_EQ(1U, array->GetCount()); CPDF_Object* obj = array->GetObjectAt(0); @@ -763,7 +756,7 @@ TEST(PDFArrayTest, CloneDirectObject) { ASSERT_TRUE(cloned_array_object); ASSERT_TRUE(cloned_array_object->IsArray()); - ScopedArray cloned_array(cloned_array_object->AsArray()); + std::unique_ptr<CPDF_Array> cloned_array(cloned_array_object->AsArray()); ASSERT_EQ(1U, cloned_array->GetCount()); CPDF_Object* cloned_obj = cloned_array->GetObjectAt(0); EXPECT_FALSE(cloned_obj); @@ -771,7 +764,7 @@ TEST(PDFArrayTest, CloneDirectObject) { TEST(PDFArrayTest, ConvertIndirect) { CPDF_IndirectObjectHolder objects_holder; - ScopedArray array(new CPDF_Array); + std::unique_ptr<CPDF_Array> array(new CPDF_Array); CPDF_Object* pObj = new CPDF_Number(42); array->Add(pObj); array->ConvertToIndirectObjectAt(0, &objects_holder); @@ -786,7 +779,7 @@ TEST(PDFArrayTest, ConvertIndirect) { TEST(PDFDictionaryTest, CloneDirectObject) { CPDF_IndirectObjectHolder objects_holder; - ScopedDict dict(new CPDF_Dictionary()); + std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary()); dict->SetReferenceFor("foo", &objects_holder, 1234); ASSERT_EQ(1U, dict->GetCount()); CPDF_Object* obj = dict->GetObjectFor("foo"); @@ -797,7 +790,8 @@ TEST(PDFDictionaryTest, CloneDirectObject) { ASSERT_TRUE(cloned_dict_object); ASSERT_TRUE(cloned_dict_object->IsDictionary()); - ScopedDict cloned_dict(cloned_dict_object->AsDictionary()); + std::unique_ptr<CPDF_Dictionary> cloned_dict( + cloned_dict_object->AsDictionary()); ASSERT_EQ(1U, cloned_dict->GetCount()); CPDF_Object* cloned_obj = cloned_dict->GetObjectFor("foo"); EXPECT_FALSE(cloned_obj); @@ -807,12 +801,12 @@ TEST(PDFObjectTest, CloneCheckLoop) { { // Create a dictionary/array pair with a reference loop. CPDF_Dictionary* dict_obj = new CPDF_Dictionary(); - ScopedArray arr_obj(new CPDF_Array); + std::unique_ptr<CPDF_Array> arr_obj(new CPDF_Array); dict_obj->SetFor("arr", arr_obj.get()); arr_obj->InsertAt(0, dict_obj); // Clone this object to see whether stack overflow will be triggered. - ScopedArray cloned_array(arr_obj->Clone()->AsArray()); + std::unique_ptr<CPDF_Array> cloned_array(arr_obj->Clone()->AsArray()); // Cloned object should be the same as the original. ASSERT_TRUE(cloned_array); EXPECT_EQ(1u, cloned_array->GetCount()); @@ -825,11 +819,12 @@ TEST(PDFObjectTest, CloneCheckLoop) { { // Create a dictionary/stream pair with a reference loop. CPDF_Dictionary* dict_obj = new CPDF_Dictionary(); - ScopedStream stream_obj(new CPDF_Stream(nullptr, 0, dict_obj)); + std::unique_ptr<CPDF_Stream> stream_obj( + new CPDF_Stream(nullptr, 0, dict_obj)); dict_obj->SetFor("stream", stream_obj.get()); // Clone this object to see whether stack overflow will be triggered. - ScopedStream cloned_stream(stream_obj->Clone()->AsStream()); + std::unique_ptr<CPDF_Stream> cloned_stream(stream_obj->Clone()->AsStream()); // Cloned object should be the same as the original. ASSERT_TRUE(cloned_stream); CPDF_Object* cloned_dict = cloned_stream->GetDict(); @@ -855,7 +850,8 @@ TEST(PDFObjectTest, CloneCheckLoop) { EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect()); // Clone this object to see whether stack overflow will be triggered. - ScopedDict cloned_dict(ToDictionary(dict_obj->CloneDirectObject())); + std::unique_ptr<CPDF_Dictionary> cloned_dict( + ToDictionary(dict_obj->CloneDirectObject())); // Cloned object should be the same as the original. ASSERT_TRUE(cloned_dict); CPDF_Object* cloned_arr = cloned_dict->GetObjectFor("arr"); @@ -869,7 +865,7 @@ TEST(PDFObjectTest, CloneCheckLoop) { TEST(PDFDictionaryTest, ConvertIndirect) { CPDF_IndirectObjectHolder objects_holder; - ScopedDict dict(new CPDF_Dictionary); + std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary); CPDF_Object* pObj = new CPDF_Number(42); dict->SetFor("clams", pObj); dict->ConvertToIndirectObjectFor("clams", &objects_holder); diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index 96e59fb62f..91f157c269 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -61,9 +61,7 @@ CPDF_Parser::CPDF_Parser() } CPDF_Parser::~CPDF_Parser() { - if (m_pTrailer) - m_pTrailer->Release(); - + delete m_pTrailer; ReleaseEncryptHandler(); SetEncryptDictionary(nullptr); @@ -72,13 +70,10 @@ CPDF_Parser::~CPDF_Parser() { m_pSyntax->m_pFileAccess = nullptr; } - for (CPDF_Dictionary* trailer : m_Trailers) { - if (trailer) - trailer->Release(); - } + for (CPDF_Dictionary* trailer : m_Trailers) + delete trailer; - if (m_pLinearized) - m_pLinearized->Release(); + delete m_pLinearized; } uint32_t CPDF_Parser::GetLastObjNum() const { @@ -357,8 +352,7 @@ bool CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { CrossRefList.insert(CrossRefList.begin(), xrefpos); LoadCrossRefV4(xrefpos, 0, true); - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( - LoadTrailerV4()); + std::unique_ptr<CPDF_Dictionary> pDict(LoadTrailerV4()); if (!pDict) return false; @@ -412,8 +406,7 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, CrossRefList.insert(CrossRefList.begin(), xrefpos); LoadCrossRefV4(xrefpos, 0, true); - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( - LoadTrailerV4()); + std::unique_ptr<CPDF_Dictionary> pDict(LoadTrailerV4()); if (!pDict) return false; @@ -590,18 +583,14 @@ bool CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) { bool CPDF_Parser::RebuildCrossRef() { m_ObjectInfo.clear(); m_SortedOffset.clear(); - if (m_pTrailer) { - m_pTrailer->Release(); - m_pTrailer = nullptr; - } + delete m_pTrailer; + m_pTrailer = nullptr; ParserState state = ParserState::kDefault; - int32_t inside_index = 0; uint32_t objnum = 0; uint32_t gennum = 0; int32_t depth = 0; - const uint32_t kBufferSize = 4096; std::vector<uint8_t> buffer(kBufferSize); @@ -755,8 +744,7 @@ bool CPDF_Parser::RebuildCrossRef() { CPDF_Object* pRoot = pDict->GetObjectFor("Root"); if (pRoot && pRoot->GetDict() && pRoot->GetDict()->GetObjectFor("Pages")) { - if (m_pTrailer) - m_pTrailer->Release(); + delete m_pTrailer; m_pTrailer = ToDictionary(pDict->Clone()); } } @@ -794,8 +782,7 @@ bool CPDF_Parser::RebuildCrossRef() { m_ObjectInfo[objnum].gennum = gennum; } - if (pObject) - pObject->Release(); + delete pObject; } --i; state = ParserState::kDefault; @@ -812,7 +799,7 @@ bool CPDF_Parser::RebuildCrossRef() { CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); if (pObj) { if (!pObj->IsDictionary() && !pObj->AsStream()) { - pObj->Release(); + delete pObj; } else { CPDF_Stream* pStream = pObj->AsStream(); if (CPDF_Dictionary* pTrailer = @@ -838,11 +825,11 @@ bool CPDF_Parser::RebuildCrossRef() { } } } - pObj->Release(); + delete pObj; } else { if (pObj->IsStream()) { m_pTrailer = ToDictionary(pTrailer->Clone()); - pObj->Release(); + delete pObj; } else { m_pTrailer = pTrailer; } @@ -859,7 +846,7 @@ bool CPDF_Parser::RebuildCrossRef() { m_pSyntax->RestorePos(dwSavePos); } } else { - pObj->Release(); + delete pObj; } } } @@ -1420,7 +1407,7 @@ CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { if (m_pSyntax->GetKeyword() != "trailer") return nullptr; - std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( + std::unique_ptr<CPDF_Object> pObj( m_pSyntax->GetObject(m_pDocument, 0, 0, true)); if (!ToDictionary(pObj.get())) return nullptr; @@ -1472,7 +1459,7 @@ bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, CPDF_Object* pLen = pDict->GetObjectFor("L"); if (!pLen) { - m_pLinearized->Release(); + delete m_pLinearized; m_pLinearized = nullptr; return false; } @@ -1488,7 +1475,7 @@ bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, return true; } - m_pLinearized->Release(); + delete m_pLinearized; m_pLinearized = nullptr; return false; } @@ -1597,12 +1584,11 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { uint32_t dwSaveMetadataObjnum = m_pSyntax->m_MetadataObjnum; m_pSyntax->m_MetadataObjnum = 0; - if (m_pTrailer) { - m_pTrailer->Release(); - m_pTrailer = nullptr; - } + delete m_pTrailer; + m_pTrailer = nullptr; m_pSyntax->RestorePos(m_LastXRefOffset - m_pSyntax->m_HeaderOffset); + uint8_t ch = 0; uint32_t dwCount = 0; m_pSyntax->GetNextChar(ch); diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp index c6e99c84b5..11ef1d2dc1 100644 --- a/core/fpdfapi/parser/cpdf_stream.cpp +++ b/core/fpdfapi/parser/cpdf_stream.cpp @@ -15,7 +15,7 @@ CPDF_Stream::CPDF_Stream() {} CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict) - : m_pDict(pDict), m_dwSize(size), m_pDataBuf(pData) {} + : m_dwSize(size), m_pDict(pDict), m_pDataBuf(pData) {} CPDF_Stream::~CPDF_Stream() { m_ObjNum = kInvalidObjNum; diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h index 73484d8335..f0ba31924e 100644 --- a/core/fpdfapi/parser/cpdf_stream.h +++ b/core/fpdfapi/parser/cpdf_stream.h @@ -20,6 +20,7 @@ class CPDF_Stream : public CPDF_Object { // Takes ownership of |pData| and |pDict|. CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict); + ~CPDF_Stream() override; // CPDF_Object. Type GetType() const override; @@ -47,20 +48,17 @@ class CPDF_Stream : public CPDF_Object { bool IsMemoryBased() const { return m_bMemoryBased; } protected: - ~CPDF_Stream() override; CPDF_Object* CloneNonCyclic( bool bDirect, std::set<const CPDF_Object*>* pVisited) const override; - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> m_pDict; bool m_bMemoryBased = true; uint32_t m_dwSize = 0; + std::unique_ptr<CPDF_Dictionary> m_pDict; std::unique_ptr<uint8_t, FxFreeDeleter> m_pDataBuf; IFX_SeekableReadStream* m_pFile = nullptr; }; -using UniqueStream = std::unique_ptr<CPDF_Stream, ReleaseDeleter<CPDF_Object>>; - inline CPDF_Stream* ToStream(CPDF_Object* obj) { return obj ? obj->AsStream() : nullptr; } @@ -69,12 +67,12 @@ inline const CPDF_Stream* ToStream(const CPDF_Object* obj) { return obj ? obj->AsStream() : nullptr; } -inline UniqueStream ToStream(UniqueObject obj) { +inline std::unique_ptr<CPDF_Stream> ToStream(std::unique_ptr<CPDF_Object> obj) { CPDF_Stream* pStream = ToStream(obj.get()); if (!pStream) return nullptr; obj.release(); - return UniqueStream(pStream); + return std::unique_ptr<CPDF_Stream>(pStream); } #endif // CORE_FPDFAPI_PARSER_CPDF_STREAM_H_ diff --git a/core/fpdfapi/parser/cpdf_string.h b/core/fpdfapi/parser/cpdf_string.h index efc6d076c7..49834c03f2 100644 --- a/core/fpdfapi/parser/cpdf_string.h +++ b/core/fpdfapi/parser/cpdf_string.h @@ -16,6 +16,7 @@ class CPDF_String : public CPDF_Object { CPDF_String(); CPDF_String(const CFX_ByteString& str, bool bHex); explicit CPDF_String(const CFX_WideString& str); + ~CPDF_String() override; // CPDF_Object. Type GetType() const override; @@ -30,8 +31,6 @@ class CPDF_String : public CPDF_Object { bool IsHex() const { return m_bHex; } protected: - ~CPDF_String() override; - CFX_ByteString m_String; bool m_bHex; }; diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp index 178af3bb9b..da3c8b0c79 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp +++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp @@ -425,8 +425,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, int32_t nKeys = 0; FX_FILESIZE dwSignValuePos = 0; - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( - new CPDF_Dictionary(m_pPool)); + std::unique_ptr<CPDF_Dictionary> pDict(new CPDF_Dictionary(m_pPool)); while (1) { CFX_ByteString key = GetNextWord(nullptr); if (key.IsEmpty()) @@ -530,8 +529,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectForStrict( } if (word == "[") { - std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( - new CPDF_Array); + std::unique_ptr<CPDF_Array> pArray(new CPDF_Array); while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) pArray->Add(pObj); @@ -544,8 +542,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectForStrict( } if (word == "<<") { - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( - new CPDF_Dictionary(m_pPool)); + std::unique_ptr<CPDF_Dictionary> pDict(new CPDF_Dictionary(m_pPool)); while (1) { FX_FILESIZE SavedPos = m_Pos; CFX_ByteString key = GetNextWord(nullptr); @@ -564,7 +561,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectForStrict( continue; key = PDF_NameDecode(key); - std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( + std::unique_ptr<CPDF_Object> obj( GetObject(pObjList, objnum, gennum, true)); if (!obj) { uint8_t ch; @@ -692,7 +689,7 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, // Can't find "endstream" or "endobj". if (endStreamOffset < 0 && endObjOffset < 0) { - pDict->Release(); + delete pDict; return nullptr; } @@ -718,7 +715,7 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, } if (len < 0) { - pDict->Release(); + delete pDict; return nullptr; } pDict->SetIntegerFor("Length", len); @@ -727,7 +724,7 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, } if (len < 0) { - pDict->Release(); + delete pDict; return nullptr; } |