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

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp

Issue 2040503002: Fix more bugs found by /analyze tool (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: style fix Created 4 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
« no previous file with comments | « no previous file | xfa/fwl/core/cfwl_widgetmgr.cpp » ('j') | xfa/fwl/core/cfwl_widgetmgr.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" 9 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 m_dwSize = dwDecryptedSize; 49 m_dwSize = dwDecryptedSize;
50 } else { 50 } else {
51 FX_BOOL bRet = PDF_DataDecode( 51 FX_BOOL bRet = PDF_DataDecode(
52 pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData, 52 pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData,
53 m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc); 53 m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc);
54 if (!bRet) { 54 if (!bRet) {
55 m_pData = pDecryptedData; 55 m_pData = pDecryptedData;
56 m_dwSize = dwDecryptedSize; 56 m_dwSize = dwDecryptedSize;
57 } 57 }
58 } 58 }
59 if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) { 59 if (pSrcData != pStream->GetRawData() && pSrcData != m_pData)
60 FX_Free(pSrcData); 60 FX_Free(pSrcData);
61 }
62 if (pDecryptedData != pSrcData && pDecryptedData != m_pData) {
63 FX_Free(pDecryptedData);
Tom Sepez 2016/06/03 18:54:37 Why is OK to remove this? We might leak.
Wei Li 2016/06/03 19:48:21 pDecryptedData is always same as pre-freed pSrcDat
64 }
65 m_pSrcData = nullptr; 61 m_pSrcData = nullptr;
66 m_bNewBuf = m_pData != pStream->GetRawData(); 62 m_bNewBuf = m_pData != pStream->GetRawData();
67 } 63 }
68 64
69 CPDF_StreamAcc::~CPDF_StreamAcc() { 65 CPDF_StreamAcc::~CPDF_StreamAcc() {
70 if (m_bNewBuf) { 66 if (m_bNewBuf)
71 FX_Free(m_pData); 67 FX_Free(m_pData);
72 }
73 FX_Free(m_pSrcData); 68 FX_Free(m_pSrcData);
74 } 69 }
75 70
76 const uint8_t* CPDF_StreamAcc::GetData() const { 71 const uint8_t* CPDF_StreamAcc::GetData() const {
77 if (m_bNewBuf) { 72 if (m_bNewBuf)
78 return m_pData; 73 return m_pData;
79 } 74 if (!m_pStream)
Tom Sepez 2016/06/03 18:54:37 nit: maybe ? oper here instead.
Wei Li 2016/06/03 19:48:21 Done.
80 if (!m_pStream) {
81 return nullptr; 75 return nullptr;
82 }
83 return m_pStream->GetRawData(); 76 return m_pStream->GetRawData();
84 } 77 }
85 78
86 uint32_t CPDF_StreamAcc::GetSize() const { 79 uint32_t CPDF_StreamAcc::GetSize() const {
87 if (m_bNewBuf) { 80 if (m_bNewBuf)
88 return m_dwSize; 81 return m_dwSize;
89 } 82 if (!m_pStream)
Tom Sepez 2016/06/03 18:54:37 ditto
Wei Li 2016/06/03 19:48:21 Done.
90 if (!m_pStream) {
91 return 0; 83 return 0;
92 }
93 return m_pStream->GetRawSize(); 84 return m_pStream->GetRawSize();
94 } 85 }
95 86
96 uint8_t* CPDF_StreamAcc::DetachData() { 87 uint8_t* CPDF_StreamAcc::DetachData() {
97 if (m_bNewBuf) { 88 if (m_bNewBuf) {
98 uint8_t* p = m_pData; 89 uint8_t* p = m_pData;
99 m_pData = nullptr; 90 m_pData = nullptr;
100 m_dwSize = 0; 91 m_dwSize = 0;
101 return p; 92 return p;
102 } 93 }
103 uint8_t* p = FX_Alloc(uint8_t, m_dwSize); 94 uint8_t* p = FX_Alloc(uint8_t, m_dwSize);
104 FXSYS_memcpy(p, m_pData, m_dwSize); 95 FXSYS_memcpy(p, m_pData, m_dwSize);
105 return p; 96 return p;
106 } 97 }
OLDNEW
« no previous file with comments | « no previous file | xfa/fwl/core/cfwl_widgetmgr.cpp » ('j') | xfa/fwl/core/cfwl_widgetmgr.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698