diff options
Diffstat (limited to 'core/fpdfapi/page/cpdf_streamcontentparser.cpp')
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 43 |
1 files changed, 24 insertions, 19 deletions
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; |