Index: core/fpdfapi/parser/cpdf_parser.cpp |
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp |
index da95cc5f249e32f17ad67a39c5cf815f11440bd0..cff0f77b3247107d4a33d724480115955f432e67 100644 |
--- a/core/fpdfapi/parser/cpdf_parser.cpp |
+++ b/core/fpdfapi/parser/cpdf_parser.cpp |
@@ -61,7 +61,9 @@ |
} |
CPDF_Parser::~CPDF_Parser() { |
- delete m_pTrailer; |
+ if (m_pTrailer) |
+ m_pTrailer->Release(); |
+ |
ReleaseEncryptHandler(); |
SetEncryptDictionary(nullptr); |
@@ -70,10 +72,13 @@ |
m_pSyntax->m_pFileAccess = nullptr; |
} |
- for (CPDF_Dictionary* trailer : m_Trailers) |
- delete trailer; |
- |
- delete m_pLinearized; |
+ for (CPDF_Dictionary* trailer : m_Trailers) { |
+ if (trailer) |
+ trailer->Release(); |
+ } |
+ |
+ if (m_pLinearized) |
+ m_pLinearized->Release(); |
} |
uint32_t CPDF_Parser::GetLastObjNum() const { |
@@ -352,7 +357,8 @@ |
CrossRefList.insert(CrossRefList.begin(), xrefpos); |
LoadCrossRefV4(xrefpos, 0, true); |
- std::unique_ptr<CPDF_Dictionary> pDict(LoadTrailerV4()); |
+ std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
+ LoadTrailerV4()); |
if (!pDict) |
return false; |
@@ -406,7 +412,8 @@ |
CrossRefList.insert(CrossRefList.begin(), xrefpos); |
LoadCrossRefV4(xrefpos, 0, true); |
- std::unique_ptr<CPDF_Dictionary> pDict(LoadTrailerV4()); |
+ std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
+ LoadTrailerV4()); |
if (!pDict) |
return false; |
@@ -583,14 +590,18 @@ |
bool CPDF_Parser::RebuildCrossRef() { |
m_ObjectInfo.clear(); |
m_SortedOffset.clear(); |
- delete m_pTrailer; |
- m_pTrailer = nullptr; |
+ if (m_pTrailer) { |
+ m_pTrailer->Release(); |
+ 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); |
@@ -744,7 +755,8 @@ |
CPDF_Object* pRoot = pDict->GetObjectFor("Root"); |
if (pRoot && pRoot->GetDict() && |
pRoot->GetDict()->GetObjectFor("Pages")) { |
- delete m_pTrailer; |
+ if (m_pTrailer) |
+ m_pTrailer->Release(); |
m_pTrailer = ToDictionary(pDict->Clone()); |
} |
} |
@@ -782,7 +794,8 @@ |
m_ObjectInfo[objnum].gennum = gennum; |
} |
- delete pObject; |
+ if (pObject) |
+ pObject->Release(); |
} |
--i; |
state = ParserState::kDefault; |
@@ -799,7 +812,7 @@ |
CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); |
if (pObj) { |
if (!pObj->IsDictionary() && !pObj->AsStream()) { |
- delete pObj; |
+ pObj->Release(); |
} else { |
CPDF_Stream* pStream = pObj->AsStream(); |
if (CPDF_Dictionary* pTrailer = |
@@ -825,11 +838,11 @@ |
} |
} |
} |
- delete pObj; |
+ pObj->Release(); |
} else { |
if (pObj->IsStream()) { |
m_pTrailer = ToDictionary(pTrailer->Clone()); |
- delete pObj; |
+ pObj->Release(); |
} else { |
m_pTrailer = pTrailer; |
} |
@@ -846,7 +859,7 @@ |
m_pSyntax->RestorePos(dwSavePos); |
} |
} else { |
- delete pObj; |
+ pObj->Release(); |
} |
} |
} |
@@ -1405,7 +1418,7 @@ |
if (m_pSyntax->GetKeyword() != "trailer") |
return nullptr; |
- std::unique_ptr<CPDF_Object> pObj( |
+ std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( |
m_pSyntax->GetObject(m_pDocument, 0, 0, true)); |
if (!ToDictionary(pObj.get())) |
return nullptr; |
@@ -1457,7 +1470,7 @@ |
CPDF_Object* pLen = pDict->GetObjectFor("L"); |
if (!pLen) { |
- delete m_pLinearized; |
+ m_pLinearized->Release(); |
m_pLinearized = nullptr; |
return false; |
} |
@@ -1473,7 +1486,7 @@ |
return true; |
} |
- delete m_pLinearized; |
+ m_pLinearized->Release(); |
m_pLinearized = nullptr; |
return false; |
} |
@@ -1582,11 +1595,12 @@ |
CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { |
uint32_t dwSaveMetadataObjnum = m_pSyntax->m_MetadataObjnum; |
m_pSyntax->m_MetadataObjnum = 0; |
- |
- delete m_pTrailer; |
- m_pTrailer = nullptr; |
+ if (m_pTrailer) { |
+ m_pTrailer->Release(); |
+ m_pTrailer = nullptr; |
+ } |
+ |
m_pSyntax->RestorePos(m_LastXRefOffset - m_pSyntax->m_HeaderOffset); |
- |
uint8_t ch = 0; |
uint32_t dwCount = 0; |
m_pSyntax->GetNextChar(ch); |