diff options
author | Lei Zhang <thestig@chromium.org> | 2015-10-26 15:43:44 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-10-26 15:43:44 -0700 |
commit | d8155ac9f49a6e8bff8d195ce1235e1bb40fc129 (patch) | |
tree | 1f71d38274b52bae34459346f766b9f9a12e7e85 /core/src/fpdfapi/fpdf_parser | |
parent | 811a4f617283a3ea22381a293b71d3c68c628905 (diff) | |
download | pdfium-d8155ac9f49a6e8bff8d195ce1235e1bb40fc129.tar.xz |
Merge to XFA: Remove default argument from CPDF_Dictionary::SetAt().
Also fix a potential object leak.
TBR=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1414963005 .
(cherry picked from commit f7992b39cec908e549fb995acae477a9efba538b)
Review URL: https://codereview.chromium.org/1421253005 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 31 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 10 |
2 files changed, 22 insertions, 19 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index 07b1a208d7..46875d88a5 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -717,27 +717,24 @@ FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const { void* value; return m_Map.Lookup(key, value); } -void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, - CPDF_Object* pObj, - CPDF_IndirectObjects* pObjs) { - ASSERT(m_Type == PDFOBJ_DICTIONARY); - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p == pObj) { + +void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj) { + ASSERT(IsDictionary()); + void* pValue = nullptr; + m_Map.Lookup(key, pValue); + CPDF_Object* pExisting = static_cast<CPDF_Object*>(pValue); + if (pExisting == pObj) return; - } - if (p) - p->Release(); - if (pObj) { - if (pObj->GetObjNum()) { - ASSERT(pObjs != NULL); - pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); - } + + if (pExisting) + pExisting->Release(); + + if (pObj) m_Map.SetAt(key, pObj); - } else { + else m_Map.RemoveKey(key); - } } + void CPDF_Dictionary::AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj) { ASSERT(m_Type == PDFOBJ_DICTIONARY); m_Map.AddValue(key, pObj); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 27cc8688cc..cbbeee6024 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -845,9 +845,15 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { FX_POSITION pos = pTrailer->GetStartPos(); while (pos) { CFX_ByteString key; - CPDF_Object* pObj = + CPDF_Object* pElement = pTrailer->GetNextElement(pos, key); - m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument); + FX_DWORD dwObjNum = pElement->GetObjNum(); + if (dwObjNum) { + m_pTrailer->SetAtReference(key, m_pDocument, + dwObjNum); + } else { + m_pTrailer->SetAt(key, pElement->Clone()); + } } pObj->Release(); } else { |