 Chromium Code Reviews
 Chromium Code Reviews Issue 1192743004:
  Cleanup: Do not check pointers before deleting them.  (Closed) 
  Base URL: https://pdfium.googlesource.com/pdfium@master
    
  
    Issue 1192743004:
  Cleanup: Do not check pointers before deleting them.  (Closed) 
  Base URL: https://pdfium.googlesource.com/pdfium@master| OLD | NEW | 
|---|---|
| 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 <utility> | 7 #include <utility> | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "../../../include/fpdfapi/fpdf_module.h" | 10 #include "../../../include/fpdfapi/fpdf_module.h" | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 FX_DWORD dwSize = m_CrossRef.GetSize(); | 61 FX_DWORD dwSize = m_CrossRef.GetSize(); | 
| 62 return dwSize ? dwSize - 1 : 0; | 62 return dwSize ? dwSize - 1 : 0; | 
| 63 } | 63 } | 
| 64 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) | 64 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) | 
| 65 { | 65 { | 
| 66 m_pEncryptDict = pDict; | 66 m_pEncryptDict = pDict; | 
| 67 } | 67 } | 
| 68 void CPDF_Parser::CloseParser(FX_BOOL bReParse) | 68 void CPDF_Parser::CloseParser(FX_BOOL bReParse) | 
| 69 { | 69 { | 
| 70 m_bVersionUpdated = FALSE; | 70 m_bVersionUpdated = FALSE; | 
| 71 if (m_pDocument && !bReParse) { | 71 if (!bReParse) { | 
| 72 delete m_pDocument; | 72 delete m_pDocument; | 
| 73 m_pDocument = NULL; | 73 m_pDocument = NULL; | 
| 74 } | 74 } | 
| 75 if (m_pTrailer) { | 75 if (m_pTrailer) { | 
| 76 m_pTrailer->Release(); | 76 m_pTrailer->Release(); | 
| 77 m_pTrailer = NULL; | 77 m_pTrailer = NULL; | 
| 78 } | 78 } | 
| 79 ReleaseEncryptHandler(); | 79 ReleaseEncryptHandler(); | 
| 80 SetEncryptDictionary(NULL); | 80 SetEncryptDictionary(NULL); | 
| 81 if (m_bOwnFileRead && m_Syntax.m_pFileAccess) { | 81 if (m_bOwnFileRead && m_Syntax.m_pFileAccess) { | 
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 delete pCryptoHandler; | 302 delete pCryptoHandler; | 
| 303 pCryptoHandler = NULL; | 303 pCryptoHandler = NULL; | 
| 304 return PDFPARSE_ERROR_HANDLER; | 304 return PDFPARSE_ERROR_HANDLER; | 
| 305 } | 305 } | 
| 306 m_Syntax.SetEncrypt(pCryptoHandler); | 306 m_Syntax.SetEncrypt(pCryptoHandler); | 
| 307 } | 307 } | 
| 308 return PDFPARSE_ERROR_SUCCESS; | 308 return PDFPARSE_ERROR_SUCCESS; | 
| 309 } | 309 } | 
| 310 void CPDF_Parser::ReleaseEncryptHandler() | 310 void CPDF_Parser::ReleaseEncryptHandler() | 
| 311 { | 311 { | 
| 312 if (m_Syntax.m_pCryptoHandler) { | 312 delete m_Syntax.m_pCryptoHandler; | 
| 313 delete m_Syntax.m_pCryptoHandler; | 313 m_Syntax.m_pCryptoHandler = NULL; | 
| 314 m_Syntax.m_pCryptoHandler = NULL; | 314 delete m_pSecurityHandler; | 
| 315 } | 315 m_pSecurityHandler = NULL; | 
| 
Tom Sepez
2015/06/19 21:13:37
still need to check !m_bForceUseSecurityHandler
 
Lei Zhang
2015/06/19 21:30:37
Done.
 | |
| 316 if (m_pSecurityHandler && !m_bForceUseSecurityHandler) { | |
| 317 delete m_pSecurityHandler; | |
| 318 m_pSecurityHandler = NULL; | |
| 319 } | |
| 320 } | 316 } | 
| 321 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) | 317 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) | 
| 322 { | 318 { | 
| 323 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 319 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 
| 324 return 0; | 320 return 0; | 
| 325 } | 321 } | 
| 326 if (m_V5Type[objnum] == 1) { | 322 if (m_V5Type[objnum] == 1) { | 
| 327 return m_CrossRef[objnum]; | 323 return m_CrossRef[objnum]; | 
| 328 } | 324 } | 
| 329 if (m_V5Type[objnum] == 2) { | 325 if (m_V5Type[objnum] == 2) { | 
| (...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1475 } | 1471 } | 
| 1476 return dwPermission; | 1472 return dwPermission; | 
| 1477 } | 1473 } | 
| 1478 FX_BOOL CPDF_Parser::IsOwner() | 1474 FX_BOOL CPDF_Parser::IsOwner() | 
| 1479 { | 1475 { | 
| 1480 return m_pSecurityHandler == NULL ? TRUE : m_pSecurityHandler->IsOwner(); | 1476 return m_pSecurityHandler == NULL ? TRUE : m_pSecurityHandler->IsOwner(); | 
| 1481 } | 1477 } | 
| 1482 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, FX_ BOOL bForced) | 1478 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, FX_ BOOL bForced) | 
| 1483 { | 1479 { | 
| 1484 ASSERT(m_pSecurityHandler == NULL); | 1480 ASSERT(m_pSecurityHandler == NULL); | 
| 1485 if (m_pSecurityHandler && !m_bForceUseSecurityHandler) { | 1481 delete m_pSecurityHandler; | 
| 
Tom Sepez
2015/06/19 21:13:37
same here.
 
Lei Zhang
2015/06/19 21:30:37
Done. I'm going to look the other way and prevent
 | |
| 1486 delete m_pSecurityHandler; | 1482 m_pSecurityHandler = NULL; | 
| 1487 m_pSecurityHandler = NULL; | |
| 1488 } | |
| 1489 m_bForceUseSecurityHandler = bForced; | 1483 m_bForceUseSecurityHandler = bForced; | 
| 1490 m_pSecurityHandler = pSecurityHandler; | 1484 m_pSecurityHandler = pSecurityHandler; | 
| 1491 if (m_bForceUseSecurityHandler) { | 1485 if (m_bForceUseSecurityHandler) { | 
| 1492 return; | 1486 return; | 
| 1493 } | 1487 } | 
| 1494 m_Syntax.m_pCryptoHandler = pSecurityHandler->CreateCryptoHandler(); | 1488 m_Syntax.m_pCryptoHandler = pSecurityHandler->CreateCryptoHandler(); | 
| 1495 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); | 1489 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); | 
| 1496 } | 1490 } | 
| 1497 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset ) | 1491 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset ) | 
| 1498 { | 1492 { | 
| (...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2977 { | 2971 { | 
| 2978 if (m_pLinearized) { | 2972 if (m_pLinearized) { | 
| 2979 m_pLinearized->Release(); | 2973 m_pLinearized->Release(); | 
| 2980 } | 2974 } | 
| 2981 if (m_pRoot) { | 2975 if (m_pRoot) { | 
| 2982 m_pRoot->Release(); | 2976 m_pRoot->Release(); | 
| 2983 } | 2977 } | 
| 2984 if (m_pTrailer) { | 2978 if (m_pTrailer) { | 
| 2985 m_pTrailer->Release(); | 2979 m_pTrailer->Release(); | 
| 2986 } | 2980 } | 
| 2987 if (m_pageMapCheckState) { | 2981 delete m_pageMapCheckState; | 
| 2988 delete m_pageMapCheckState; | 2982 delete m_pagesLoadState; | 
| 2989 } | |
| 2990 if (m_pagesLoadState) { | |
| 2991 delete m_pagesLoadState; | |
| 2992 } | |
| 2993 int32_t i = 0; | 2983 int32_t i = 0; | 
| 2994 int32_t iSize = m_arrayAcroforms.GetSize(); | 2984 int32_t iSize = m_arrayAcroforms.GetSize(); | 
| 2995 for (i = 0; i < iSize; ++i) { | 2985 for (i = 0; i < iSize; ++i) { | 
| 2996 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); | 2986 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); | 
| 2997 } | 2987 } | 
| 2998 } | 2988 } | 
| 2999 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) | 2989 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) | 
| 3000 { | 2990 { | 
| 3001 m_pDocument = pDoc; | 2991 m_pDocument = pDoc; | 
| 3002 } | 2992 } | 
| (...skipping 1630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4633 iLow = iMid + 1; | 4623 iLow = iMid + 1; | 
| 4634 } | 4624 } | 
| 4635 } | 4625 } | 
| 4636 iNext = iLow; | 4626 iNext = iLow; | 
| 4637 return FALSE; | 4627 return FALSE; | 
| 4638 } | 4628 } | 
| 4639 CPDF_PageNode::~CPDF_PageNode() | 4629 CPDF_PageNode::~CPDF_PageNode() | 
| 4640 { | 4630 { | 
| 4641 int32_t iSize = m_childNode.GetSize(); | 4631 int32_t iSize = m_childNode.GetSize(); | 
| 4642 for (int32_t i = 0; i < iSize; ++i) { | 4632 for (int32_t i = 0; i < iSize; ++i) { | 
| 4643 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i]; | 4633 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 
| 4644 if (pNode) { | 4634 delete pNode; | 
| 4645 delete pNode; | |
| 4646 } | |
| 4647 } | 4635 } | 
| 4648 m_childNode.RemoveAll(); | 4636 m_childNode.RemoveAll(); | 
| 4649 } | 4637 } | 
| OLD | NEW |