Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp

Issue 1514093002: Fix memory leaks involving InsertIndirectObject() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/include/fpdfapi/fpdf_parser.h" 7 #include "core/include/fpdfapi/fpdf_parser.h"
8 8
9 #include "core/include/fxcrt/fx_string.h" 9 #include "core/include/fxcrt/fx_string.h"
10 10
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 void CPDF_IndirectObjects::ReleaseIndirectObject(FX_DWORD objnum) { 1149 void CPDF_IndirectObjects::ReleaseIndirectObject(FX_DWORD objnum) {
1150 void* value; 1150 void* value;
1151 if (!m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) 1151 if (!m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value))
1152 return; 1152 return;
1153 CPDF_Object* pValue = static_cast<CPDF_Object*>(value); 1153 CPDF_Object* pValue = static_cast<CPDF_Object*>(value);
1154 if (pValue->GetObjNum() == -1) 1154 if (pValue->GetObjNum() == -1)
1155 return; 1155 return;
1156 pValue->Destroy(); 1156 pValue->Destroy();
1157 m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum); 1157 m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum);
1158 } 1158 }
1159 void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, 1159 FX_BOOL CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum,
1160 CPDF_Object* pObj) { 1160 CPDF_Object* pObj) {
1161 if (objnum == 0 || pObj == NULL) { 1161 if (!objnum || !pObj)
1162 return; 1162 return FALSE;
1163 } 1163 void* value = nullptr;
1164 void* value = NULL;
1165 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { 1164 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) {
1166 if (value) { 1165 if (value) {
1167 CPDF_Object* pValue = static_cast<CPDF_Object*>(value); 1166 CPDF_Object* pExistingObj = static_cast<CPDF_Object*>(value);
1168 if (pObj->GetGenNum() <= pValue->GetGenNum()) 1167 if (pObj->GetGenNum() <= pExistingObj->GetGenNum()) {
1169 return; 1168 pObj->Destroy();
1170 pValue->Destroy(); 1169 return FALSE;
1170 }
1171 pExistingObj->Destroy();
1171 } 1172 }
1172 } 1173 }
1173 pObj->m_ObjNum = objnum; 1174 pObj->m_ObjNum = objnum;
1174 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); 1175 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj);
1175 if (m_LastObjNum < objnum) { 1176 if (m_LastObjNum < objnum)
1176 m_LastObjNum = objnum; 1177 m_LastObjNum = objnum;
1177 } 1178 return TRUE;
1178 } 1179 }
1179 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { 1180 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const {
1180 return m_LastObjNum; 1181 return m_LastObjNum;
1181 } 1182 }
OLDNEW
« no previous file with comments | « core/include/fpdfapi/fpdf_objects.h ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698