diff options
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r-- | core/fpdfapi/page/cpdf_contentmark.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_contentmarkitem.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_contentmarkitem.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_image.cpp | 18 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_image.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 43 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/fpdf_page_parser_old.cpp | 16 |
8 files changed, 53 insertions, 43 deletions
diff --git a/core/fpdfapi/page/cpdf_contentmark.cpp b/core/fpdfapi/page/cpdf_contentmark.cpp index a867409335..d60e144d6e 100644 --- a/core/fpdfapi/page/cpdf_contentmark.cpp +++ b/core/fpdfapi/page/cpdf_contentmark.cpp @@ -110,7 +110,8 @@ void CPDF_ContentMark::MarkData::AddMark(const CFX_ByteString& name, if (pDict) { if (bDirect) { item.SetDirectDict( - std::unique_ptr<CPDF_Dictionary>(ToDictionary(pDict->Clone()))); + std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>( + ToDictionary(pDict->Clone()))); } else { item.SetPropertiesDict(pDict); } diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.cpp b/core/fpdfapi/page/cpdf_contentmarkitem.cpp index dffeada707..597f8a595c 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.cpp +++ b/core/fpdfapi/page/cpdf_contentmarkitem.cpp @@ -39,7 +39,7 @@ bool CPDF_ContentMarkItem::HasMCID() const { } void CPDF_ContentMarkItem::SetDirectDict( - std::unique_ptr<CPDF_Dictionary> pDict) { + std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict) { m_ParamType = DirectDict; m_pDirectDict = std::move(pDict); } diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.h b/core/fpdfapi/page/cpdf_contentmarkitem.h index ed2737111b..f1f06c3a38 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.h +++ b/core/fpdfapi/page/cpdf_contentmarkitem.h @@ -31,14 +31,16 @@ class CPDF_ContentMarkItem { bool HasMCID() const; void SetName(const CFX_ByteString& name) { m_MarkName = name; } - void SetDirectDict(std::unique_ptr<CPDF_Dictionary> pDict); + void SetDirectDict( + std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict); void SetPropertiesDict(CPDF_Dictionary* pDict); private: CFX_ByteString m_MarkName; ParamType m_ParamType; CPDF_Dictionary* m_pPropertiesDict; // not owned. - std::unique_ptr<CPDF_Dictionary> m_pDirectDict; + std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> + m_pDirectDict; }; #endif // CORE_FPDFAPI_PAGE_CPDF_CONTENTMARKITEM_H_ diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index 976d6d8c47..23c6e4f786 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -25,16 +25,14 @@ CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} -CPDF_Image::CPDF_Image(CPDF_Document* pDoc, - std::unique_ptr<CPDF_Stream> pStream) +CPDF_Image::CPDF_Image(CPDF_Document* pDoc, UniqueStream pStream) : m_pDocument(pDoc), m_pStream(pStream.get()), m_pOwnedStream(std::move(pStream)) { if (!m_pStream) return; - m_pOwnedDict = - ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone())); + m_pOwnedDict = ToDictionary(UniqueObject(m_pStream->GetDict()->Clone())); m_pDict = m_pOwnedDict.get(); FinishInitialization(); } @@ -63,15 +61,13 @@ void CPDF_Image::FinishInitialization() { CPDF_Image* CPDF_Image::Clone() { CPDF_Image* pImage = new CPDF_Image(m_pDocument); if (m_pOwnedStream) { - pImage->m_pOwnedStream = - ToStream(std::unique_ptr<CPDF_Object>(m_pOwnedStream->Clone())); + pImage->m_pOwnedStream = ToStream(UniqueObject(m_pOwnedStream->Clone())); pImage->m_pStream = pImage->m_pOwnedStream.get(); } else { pImage->m_pStream = m_pStream; } if (m_pOwnedDict) { - pImage->m_pOwnedDict = - ToDictionary(std::unique_ptr<CPDF_Object>(m_pOwnedDict->Clone())); + pImage->m_pOwnedDict = ToDictionary(UniqueObject(m_pOwnedDict->Clone())); pImage->m_pDict = pImage->m_pOwnedDict.get(); } else { pImage->m_pDict = m_pDict; @@ -293,8 +289,10 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) { pNewBitmap->Copy(pBitmap); pNewBitmap->ConvertFormat(FXDIB_Rgb); SetImage(pNewBitmap, iCompress); - delete pDict; - pDict = nullptr; + if (pDict) { + pDict->Release(); + pDict = nullptr; + } FX_Free(dest_buf); dest_buf = nullptr; dest_size = 0; diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h index 02308db647..f619845597 100644 --- a/core/fpdfapi/page/cpdf_image.h +++ b/core/fpdfapi/page/cpdf_image.h @@ -28,7 +28,7 @@ class IFX_SeekableWriteStream; class CPDF_Image { public: explicit CPDF_Image(CPDF_Document* pDoc); - CPDF_Image(CPDF_Document* pDoc, std::unique_ptr<CPDF_Stream> pStream); + CPDF_Image(CPDF_Document* pDoc, UniqueStream pStream); CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum); ~CPDF_Image(); @@ -84,8 +84,8 @@ class CPDF_Image { CPDF_Document* const m_pDocument; CPDF_Stream* m_pStream = nullptr; CPDF_Dictionary* m_pDict = nullptr; - std::unique_ptr<CPDF_Stream> m_pOwnedStream; - std::unique_ptr<CPDF_Dictionary> m_pOwnedDict; + UniqueStream m_pOwnedStream; + UniqueDictionary m_pOwnedDict; CPDF_Dictionary* m_pOC = nullptr; }; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 7618f8271f..ed6701382c 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -180,8 +180,12 @@ CPDF_StreamContentParser::CPDF_StreamContentParser( CPDF_StreamContentParser::~CPDF_StreamContentParser() { ClearAllParams(); FX_Free(m_pPathPoints); - delete m_pLastImageDict; - delete m_pLastCloneImageDict; + if (m_pLastImageDict) { + m_pLastImageDict->Release(); + } + if (m_pLastCloneImageDict) { + m_pLastCloneImageDict->Release(); + } } int CPDF_StreamContentParser::GetNextParamPos() { @@ -190,9 +194,10 @@ int CPDF_StreamContentParser::GetNextParamPos() { if (m_ParamStartPos == kParamBufSize) { m_ParamStartPos = 0; } - if (m_ParamBuf[m_ParamStartPos].m_Type == 0) - delete m_ParamBuf[m_ParamStartPos].m_pObject; - + if (m_ParamBuf[m_ParamStartPos].m_Type == 0) { + if (CPDF_Object* pObject = m_ParamBuf[m_ParamStartPos].m_pObject) + pObject->Release(); + } return m_ParamStartPos; } int index = m_ParamStartPos + m_ParamCount; @@ -239,9 +244,10 @@ void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { void CPDF_StreamContentParser::ClearAllParams() { uint32_t index = m_ParamStartPos; for (uint32_t i = 0; i < m_ParamCount; i++) { - if (m_ParamBuf[index].m_Type == 0) - delete m_ParamBuf[index].m_pObject; - + if (m_ParamBuf[index].m_Type == 0) { + if (CPDF_Object* pObject = m_ParamBuf[index].m_pObject) + pObject->Release(); + } index++; if (index == kParamBufSize) { index = 0; @@ -525,7 +531,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { m_pSyntax->GetWordSize()); if (bsKeyword != "ID") { m_pSyntax->SetPos(savePos); - delete pDict; + pDict->Release(); return; } } @@ -534,7 +540,8 @@ void CPDF_StreamContentParser::Handle_BeginImage() { } CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, m_pSyntax->GetWordSize() - 1); - std::unique_ptr<CPDF_Object> pObj(m_pSyntax->ReadNextObject(false, 0)); + std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( + m_pSyntax->ReadNextObject(false, 0)); if (!key.IsEmpty()) { uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; if (dwObjNum) @@ -559,8 +566,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { } } pDict->SetNameFor("Subtype", "Image"); - std::unique_ptr<CPDF_Stream> pStream( - m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); + UniqueStream pStream(m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); bool bGaveDictAway = !!pStream; while (1) { CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); @@ -577,7 +583,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { } CPDF_ImageObject* pImgObj = AddImage(std::move(pStream)); if (!pImgObj && !bGaveDictAway) - delete pDict; + pDict->Release(); } void CPDF_StreamContentParser::Handle_BeginMarkedContent() { @@ -663,10 +669,10 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() { type = pXObject->GetDict()->GetStringFor("Subtype"); if (type == "Image") { - CPDF_ImageObject* pObj = pXObject->IsInline() - ? AddImage(std::unique_ptr<CPDF_Stream>( - ToStream(pXObject->Clone()))) - : AddImage(pXObject->GetObjNum()); + CPDF_ImageObject* pObj = + pXObject->IsInline() + ? AddImage(UniqueStream(ToStream(pXObject->Clone()))) + : AddImage(pXObject->GetObjNum()); m_LastImageName = name; m_pLastImage = pObj->GetImage(); @@ -698,8 +704,7 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj)); } -CPDF_ImageObject* CPDF_StreamContentParser::AddImage( - std::unique_ptr<CPDF_Stream> pStream) { +CPDF_ImageObject* CPDF_StreamContentParser::AddImage(UniqueStream pStream) { if (!pStream) return nullptr; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.h b/core/fpdfapi/page/cpdf_streamcontentparser.h index 1ed2aaa4de..58008da96a 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.h +++ b/core/fpdfapi/page/cpdf_streamcontentparser.h @@ -97,7 +97,7 @@ class CPDF_StreamContentParser { void AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag); void AddPathRect(FX_FLOAT x, FX_FLOAT y, FX_FLOAT w, FX_FLOAT h); void AddPathObject(int FillType, bool bStroke); - CPDF_ImageObject* AddImage(std::unique_ptr<CPDF_Stream> pStream); + CPDF_ImageObject* AddImage(UniqueStream pStream); CPDF_ImageObject* AddImage(uint32_t streamObjNum); CPDF_ImageObject* AddImage(CPDF_Image* pImage); diff --git a/core/fpdfapi/page/fpdf_page_parser_old.cpp b/core/fpdfapi/page/fpdf_page_parser_old.cpp index 51ffc11b03..0d1db43825 100644 --- a/core/fpdfapi/page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/page/fpdf_page_parser_old.cpp @@ -138,7 +138,9 @@ CPDF_StreamParser::CPDF_StreamParser( m_pPool(pPool) {} CPDF_StreamParser::~CPDF_StreamParser() { - delete m_pLastObj; + if (m_pLastObj) { + m_pLastObj->Release(); + } } CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, @@ -250,8 +252,10 @@ CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, } CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { - delete m_pLastObj; - m_pLastObj = nullptr; + if (m_pLastObj) { + m_pLastObj->Release(); + m_pLastObj = nullptr; + } m_WordSize = 0; bool bIsNumber = true; @@ -370,7 +374,7 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(bool bAllowNestedArray, break; if (!m_WordSize || m_WordBuffer[0] != '/') { - delete pDict; + pDict->Release(); return nullptr; } @@ -378,12 +382,12 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(bool bAllowNestedArray, PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); CPDF_Object* pObj = ReadNextObject(true, 0); if (!pObj) { - delete pDict; + pDict->Release(); return nullptr; } if (key.IsEmpty()) - delete pObj; + pObj->Release(); else pDict->SetFor(key, pObj); } |