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

Side by Side Diff: core/src/fxcodec/jbig2/JBig2_Context.cpp

Issue 1192743004: Cleanup: Do not check pointers before deleting them. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 6 months 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 <map> 7 #include <map>
8 #include <list> 8 #include <list>
9 #include "JBig2_Context.h" 9 #include "JBig2_Context.h"
10 10
(...skipping 12 matching lines...) Expand all
23 return; 23 return;
24 } 24 }
25 } 25 }
26 CJBig2_Context *CJBig2_Context::CreateContext(CJBig2_Module *pModule, uint8_t *p GlobalData, FX_DWORD dwGlobalLength, 26 CJBig2_Context *CJBig2_Context::CreateContext(CJBig2_Module *pModule, uint8_t *p GlobalData, FX_DWORD dwGlobalLength,
27 uint8_t *pData, FX_DWORD dwLength, int32_t nStreamType, std::list<CJBig2 _CachePair>* pSymbolDictCache, IFX_Pause* pPause) 27 uint8_t *pData, FX_DWORD dwLength, int32_t nStreamType, std::list<CJBig2 _CachePair>* pSymbolDictCache, IFX_Pause* pPause)
28 { 28 {
29 return new(pModule)CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLeng th, nStreamType, pSymbolDictCache, pPause); 29 return new(pModule)CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLeng th, nStreamType, pSymbolDictCache, pPause);
30 } 30 }
31 void CJBig2_Context::DestroyContext(CJBig2_Context *pContext) 31 void CJBig2_Context::DestroyContext(CJBig2_Context *pContext)
32 { 32 {
33 if(pContext) { 33 delete pContext;
34 delete pContext;
35 }
36 } 34 }
37 CJBig2_Context::CJBig2_Context(uint8_t *pGlobalData, FX_DWORD dwGlobalLength, 35 CJBig2_Context::CJBig2_Context(uint8_t *pGlobalData, FX_DWORD dwGlobalLength,
38 uint8_t *pData, FX_DWORD dwLength, int32_t nStrea mType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause) 36 uint8_t *pData, FX_DWORD dwLength, int32_t nStrea mType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause)
39 { 37 {
40 if(pGlobalData && (dwGlobalLength > 0)) { 38 if(pGlobalData && (dwGlobalLength > 0)) {
41 JBIG2_ALLOC(m_pGlobalContext, CJBig2_Context(NULL, 0, pGlobalData, dwGlo balLength, 39 JBIG2_ALLOC(m_pGlobalContext, CJBig2_Context(NULL, 0, pGlobalData, dwGlo balLength,
42 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); 40 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause));
43 } else { 41 } else {
44 m_pGlobalContext = NULL; 42 m_pGlobalContext = NULL;
45 } 43 }
(...skipping 10 matching lines...) Expand all
56 m_pArithDecoder = NULL; 54 m_pArithDecoder = NULL;
57 m_pGRD = NULL; 55 m_pGRD = NULL;
58 m_gbContext = NULL; 56 m_gbContext = NULL;
59 m_pSegment = NULL; 57 m_pSegment = NULL;
60 m_dwOffset = 0; 58 m_dwOffset = 0;
61 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; 59 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY;
62 m_pSymbolDictCache = pSymbolDictCache; 60 m_pSymbolDictCache = pSymbolDictCache;
63 } 61 }
64 CJBig2_Context::~CJBig2_Context() 62 CJBig2_Context::~CJBig2_Context()
65 { 63 {
66 if(m_pArithDecoder) { 64 delete m_pArithDecoder;
67 delete m_pArithDecoder;
68 }
69 m_pArithDecoder = NULL; 65 m_pArithDecoder = NULL;
70 if(m_pGRD) { 66 delete m_pGRD;
71 delete m_pGRD;
72 }
73 m_pGRD = NULL; 67 m_pGRD = NULL;
74 if(m_gbContext) { 68 if(m_gbContext) {
75 m_pModule->JBig2_Free(m_gbContext); 69 m_pModule->JBig2_Free(m_gbContext);
76 } 70 }
77 m_gbContext = NULL; 71 m_gbContext = NULL;
78 if(m_pGlobalContext) { 72 delete m_pGlobalContext;
79 delete m_pGlobalContext;
80 }
81 m_pGlobalContext = NULL; 73 m_pGlobalContext = NULL;
82 if(m_pPageInfoList) { 74 delete m_pPageInfoList;
83 delete m_pPageInfoList;
84 }
85 m_pPageInfoList = NULL; 75 m_pPageInfoList = NULL;
86 if(m_bBufSpecified && m_pPage) { 76 if(m_bBufSpecified) {
87 delete m_pPage; 77 delete m_pPage;
88 } 78 }
89 m_pPage = NULL; 79 m_pPage = NULL;
90 if(m_pStream) { 80 delete m_pStream;
91 delete m_pStream;
92 }
93 m_pStream = NULL; 81 m_pStream = NULL;
94 if(m_pSegmentList) { 82 delete m_pSegmentList;
95 delete m_pSegmentList;
96 }
97 m_pSegmentList = NULL; 83 m_pSegmentList = NULL;
98 } 84 }
99 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) 85 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause)
100 { 86 {
101 uint8_t cFlags; 87 uint8_t cFlags;
102 FX_DWORD dwTemp; 88 FX_DWORD dwTemp;
103 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A}; 89 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A};
104 int32_t nRet; 90 int32_t nRet;
105 if(m_pStream->getByteLeft() < 8) { 91 if(m_pStream->getByteLeft() < 8) {
106 m_pModule->JBig2_Error("file header too short."); 92 m_pModule->JBig2_Error("file header too short.");
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 int32_t nRet = 0; 226 int32_t nRet = 0;
241 if(m_pGlobalContext) { 227 if(m_pGlobalContext) {
242 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); 228 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause);
243 if(nRet != JBIG2_SUCCESS) { 229 if(nRet != JBIG2_SUCCESS) {
244 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; 230 m_ProcessiveStatus = FXCODEC_STATUS_ERROR;
245 return nRet; 231 return nRet;
246 } 232 }
247 } 233 }
248 m_bFirstPage = TRUE; 234 m_bFirstPage = TRUE;
249 m_PauseStep = 0; 235 m_PauseStep = 0;
250 if(m_pPage) { 236 delete m_pPage;
251 delete m_pPage;
252 }
253 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); 237 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf));
254 m_bBufSpecified = TRUE; 238 m_bBufSpecified = TRUE;
255 if(m_pPage && pPause && pPause->NeedToPauseNow()) { 239 if(m_pPage && pPause && pPause->NeedToPauseNow()) {
256 m_PauseStep = 1; 240 m_PauseStep = 1;
257 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; 241 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
258 return nRet; 242 return nRet;
259 } 243 }
260 int ret = Continue(pPause); 244 int ret = Continue(pPause);
261 return ret; 245 return ret;
262 } 246 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } else { 293 } else {
310 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; 294 m_ProcessiveStatus = FXCODEC_STATUS_ERROR;
311 } 295 }
312 return nRet; 296 return nRet;
313 } 297 }
314 int32_t CJBig2_Context::getNextPage(uint8_t *pBuf, int32_t width, int32_t height , int32_t stride, IFX_Pause* pPause) 298 int32_t CJBig2_Context::getNextPage(uint8_t *pBuf, int32_t width, int32_t height , int32_t stride, IFX_Pause* pPause)
315 { 299 {
316 int32_t nRet = JBIG2_ERROR_STREAM_TYPE; 300 int32_t nRet = JBIG2_ERROR_STREAM_TYPE;
317 m_bFirstPage = FALSE; 301 m_bFirstPage = FALSE;
318 m_PauseStep = 0; 302 m_PauseStep = 0;
319 if(m_pPage) { 303 delete m_pPage;
320 delete m_pPage;
321 }
322 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); 304 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf));
323 m_bBufSpecified = TRUE; 305 m_bBufSpecified = TRUE;
324 if(m_pPage && pPause && pPause->NeedToPauseNow()) { 306 if(m_pPage && pPause && pPause->NeedToPauseNow()) {
325 m_PauseStep = 1; 307 m_PauseStep = 1;
326 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; 308 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
327 return nRet; 309 return nRet;
328 } 310 }
329 return Continue(pPause); 311 return Continue(pPause);
330 switch(m_nStreamType) { 312 switch(m_nStreamType) {
331 case JBIG2_FILE_STREAM: 313 case JBIG2_FILE_STREAM:
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 delete pPageInfo; 546 delete pPageInfo;
565 goto failed1; 547 goto failed1;
566 } 548 }
567 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0; 549 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0;
568 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; 550 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff;
569 if((pPageInfo->m_dwHeight == 0xffffffff) && (pPageInfo->m_bIsStr iped != 1)) { 551 if((pPageInfo->m_dwHeight == 0xffffffff) && (pPageInfo->m_bIsStr iped != 1)) {
570 m_pModule->JBig2_Warn("page height = 0xffffffff buf stripe f ield is 0"); 552 m_pModule->JBig2_Warn("page height = 0xffffffff buf stripe f ield is 0");
571 pPageInfo->m_bIsStriped = 1; 553 pPageInfo->m_bIsStriped = 1;
572 } 554 }
573 if(!m_bBufSpecified) { 555 if(!m_bBufSpecified) {
574 if(m_pPage) { 556 delete m_pPage;
575 delete m_pPage;
576 }
577 if(pPageInfo->m_dwHeight == 0xffffffff) { 557 if(pPageInfo->m_dwHeight == 0xffffffff) {
578 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, pPageInfo->m_wMaxStripeSize)); 558 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, pPageInfo->m_wMaxStripeSize));
579 } else { 559 } else {
580 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, pPageInfo->m_dwHeight)); 560 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, pPageInfo->m_dwHeight));
581 } 561 }
582 } 562 }
583 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); 563 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0);
584 m_pPageInfoList->addItem(pPageInfo); 564 m_pPageInfoList->addItem(pPageInfo);
585 m_nState = JBIG2_IN_PAGE; 565 m_nState = JBIG2_IN_PAGE;
586 } 566 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 pSegment->m_Result.sd->m_grContext = grContext; 833 pSegment->m_Result.sd->m_grContext = grContext;
854 } 834 }
855 bUsed = TRUE; 835 bUsed = TRUE;
856 } else { 836 } else {
857 bUsed = FALSE; 837 bUsed = FALSE;
858 } 838 }
859 delete pSymbolDictDecoder; 839 delete pSymbolDictDecoder;
860 if(SDINSYMS) { 840 if(SDINSYMS) {
861 m_pModule->JBig2_Free(SDINSYMS); 841 m_pModule->JBig2_Free(SDINSYMS);
862 } 842 }
863 if(Table_B1) { 843 delete Table_B1;
864 delete Table_B1; 844 delete Table_B2;
865 } 845 delete Table_B3;
866 if(Table_B2) { 846 delete Table_B4;
867 delete Table_B2; 847 delete Table_B5;
868 }
869 if(Table_B3) {
870 delete Table_B3;
871 }
872 if(Table_B4) {
873 delete Table_B4;
874 }
875 if(Table_B5) {
876 delete Table_B5;
877 }
878 if(bUsed == FALSE) { 848 if(bUsed == FALSE) {
879 if(gbContext) { 849 if(gbContext) {
880 m_pModule->JBig2_Free(gbContext); 850 m_pModule->JBig2_Free(gbContext);
881 } 851 }
882 if(grContext) { 852 if(grContext) {
883 m_pModule->JBig2_Free(grContext); 853 m_pModule->JBig2_Free(grContext);
884 } 854 }
885 } 855 }
886 return JBIG2_SUCCESS; 856 return JBIG2_SUCCESS;
887 failed: 857 failed:
888 delete pSymbolDictDecoder; 858 delete pSymbolDictDecoder;
889 if(SDINSYMS) { 859 if(SDINSYMS) {
890 m_pModule->JBig2_Free(SDINSYMS); 860 m_pModule->JBig2_Free(SDINSYMS);
891 } 861 }
892 if(Table_B1) { 862 delete Table_B1;
893 delete Table_B1; 863 delete Table_B2;
894 } 864 delete Table_B3;
895 if(Table_B2) { 865 delete Table_B4;
896 delete Table_B2; 866 delete Table_B5;
897 }
898 if(Table_B3) {
899 delete Table_B3;
900 }
901 if(Table_B4) {
902 delete Table_B4;
903 }
904 if(Table_B5) {
905 delete Table_B5;
906 }
907 if(gbContext) { 867 if(gbContext) {
908 m_pModule->JBig2_Free(gbContext); 868 m_pModule->JBig2_Free(gbContext);
909 } 869 }
910 if(grContext) { 870 if(grContext) {
911 m_pModule->JBig2_Free(grContext); 871 m_pModule->JBig2_Free(grContext);
912 } 872 }
913 return nRet; 873 return nRet;
914 } 874 }
915 875
916 FX_BOOL CJBig2_Context::parseTextRegion(CJBig2_Segment *pSegment) 876 FX_BOOL CJBig2_Context::parseTextRegion(CJBig2_Segment *pSegment)
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 delete pTRD; 1195 delete pTRD;
1236 if(SBSYMS) { 1196 if(SBSYMS) {
1237 m_pModule->JBig2_Free(SBSYMS); 1197 m_pModule->JBig2_Free(SBSYMS);
1238 } 1198 }
1239 if(SBSYMCODES) { 1199 if(SBSYMCODES) {
1240 m_pModule->JBig2_Free(SBSYMCODES); 1200 m_pModule->JBig2_Free(SBSYMCODES);
1241 } 1201 }
1242 if(grContext) { 1202 if(grContext) {
1243 m_pModule->JBig2_Free(grContext); 1203 m_pModule->JBig2_Free(grContext);
1244 } 1204 }
1245 if(Table_B1) { 1205 delete Table_B1;
1246 delete Table_B1; 1206 delete Table_B6;
1247 } 1207 delete Table_B7;
1248 if(Table_B6) { 1208 delete Table_B8;
1249 delete Table_B6; 1209 delete Table_B9;
1250 } 1210 delete Table_B10;
1251 if(Table_B7) { 1211 delete Table_B11;
1252 delete Table_B7; 1212 delete Table_B12;
1253 } 1213 delete Table_B13;
1254 if(Table_B8) { 1214 delete Table_B14;
1255 delete Table_B8; 1215 delete Table_B15;
1256 }
1257 if(Table_B9) {
1258 delete Table_B9;
1259 }
1260 if(Table_B10) {
1261 delete Table_B10;
1262 }
1263 if(Table_B11) {
1264 delete Table_B11;
1265 }
1266 if(Table_B12) {
1267 delete Table_B12;
1268 }
1269 if(Table_B13) {
1270 delete Table_B13;
1271 }
1272 if(Table_B14) {
1273 delete Table_B14;
1274 }
1275 if(Table_B15) {
1276 delete Table_B15;
1277 }
1278 return JBIG2_SUCCESS; 1216 return JBIG2_SUCCESS;
1279 failed: 1217 failed:
1280 delete pTRD; 1218 delete pTRD;
1281 if(SBSYMS) { 1219 if(SBSYMS) {
1282 m_pModule->JBig2_Free(SBSYMS); 1220 m_pModule->JBig2_Free(SBSYMS);
1283 } 1221 }
1284 if(SBSYMCODES) { 1222 if(SBSYMCODES) {
1285 m_pModule->JBig2_Free(SBSYMCODES); 1223 m_pModule->JBig2_Free(SBSYMCODES);
1286 } 1224 }
1287 if(grContext) { 1225 if(grContext) {
1288 m_pModule->JBig2_Free(grContext); 1226 m_pModule->JBig2_Free(grContext);
1289 } 1227 }
1290 if(Table_B1) { 1228 delete Table_B1;
1291 delete Table_B1; 1229 delete Table_B6;
1292 } 1230 delete Table_B7;
1293 if(Table_B6) { 1231 delete Table_B8;
1294 delete Table_B6; 1232 delete Table_B9;
1295 } 1233 delete Table_B10;
1296 if(Table_B7) { 1234 delete Table_B11;
1297 delete Table_B7; 1235 delete Table_B12;
1298 } 1236 delete Table_B13;
1299 if(Table_B8) { 1237 delete Table_B14;
1300 delete Table_B8; 1238 delete Table_B15;
1301 }
1302 if(Table_B9) {
1303 delete Table_B9;
1304 }
1305 if(Table_B10) {
1306 delete Table_B10;
1307 }
1308 if(Table_B11) {
1309 delete Table_B11;
1310 }
1311 if(Table_B12) {
1312 delete Table_B12;
1313 }
1314 if(Table_B13) {
1315 delete Table_B13;
1316 }
1317 if(Table_B14) {
1318 delete Table_B14;
1319 }
1320 if(Table_B15) {
1321 delete Table_B15;
1322 }
1323 return nRet; 1239 return nRet;
1324 } 1240 }
1325 1241
1326 FX_BOOL CJBig2_Context::parsePatternDict(CJBig2_Segment *pSegment, IFX_Pause* pP ause) 1242 FX_BOOL CJBig2_Context::parsePatternDict(CJBig2_Segment *pSegment, IFX_Pause* pP ause)
1327 { 1243 {
1328 FX_DWORD dwTemp; 1244 FX_DWORD dwTemp;
1329 uint8_t cFlags; 1245 uint8_t cFlags;
1330 JBig2ArithCtx *gbContext; 1246 JBig2ArithCtx *gbContext;
1331 CJBig2_ArithDecoder *pArithDecoder; 1247 CJBig2_ArithDecoder *pArithDecoder;
1332 CJBig2_PDDProc *pPDD; 1248 CJBig2_PDDProc *pPDD;
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1838 SBSYMCODES[CURTEMP].code = CURCODE; 1754 SBSYMCODES[CURTEMP].code = CURCODE;
1839 CURCODE = CURCODE + 1; 1755 CURCODE = CURCODE + 1;
1840 } 1756 }
1841 CURTEMP = CURTEMP + 1; 1757 CURTEMP = CURTEMP + 1;
1842 } 1758 }
1843 CURLEN = CURLEN + 1; 1759 CURLEN = CURLEN + 1;
1844 } 1760 }
1845 m_pModule->JBig2_Free(LENCOUNT); 1761 m_pModule->JBig2_Free(LENCOUNT);
1846 m_pModule->JBig2_Free(FIRSTCODE); 1762 m_pModule->JBig2_Free(FIRSTCODE);
1847 } 1763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698