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

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_imageobject.cpp

Issue 2194393002: Fix a leak with FPDFPageObj_NewImgeObj(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 4 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 | « core/fpdfapi/fpdf_page/cpdf_image.cpp ('k') | core/fpdfapi/fpdf_page/fpdf_page_doc.cpp » ('j') | no next file with comments »
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_page/include/cpdf_imageobject.h" 7 #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h"
8 8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" 9 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
10 #include "core/fpdfapi/fpdf_page/pageint.h" 10 #include "core/fpdfapi/fpdf_page/pageint.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
12 12
13 CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {} 13 CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {}
14 14
15 CPDF_ImageObject::~CPDF_ImageObject() { 15 CPDF_ImageObject::~CPDF_ImageObject() {
16 if (!m_pImage) { 16 if (!m_pImage)
17 return;
18
19 if (m_pImage->CanRelease()) {
20 m_pImage->Release();
17 return; 21 return;
18 } 22 }
19 if (m_pImage->IsInline() || 23
20 (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) { 24 auto* pPageData = m_pImage->GetDocument()->GetPageData();
21 delete m_pImage; 25 if (pPageData->ReleaseImage(m_pImage->GetStream()))
22 } else { 26 return;
23 m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream()); 27
24 } 28 delete m_pImage;
Lei Zhang 2016/08/01 22:08:03 Not sure what else we can do here.
Wei Li 2016/08/04 18:00:39 I suspect this might not be the right thing to do.
Lei Zhang 2016/08/04 21:58:25 Does you comment apply to patch set 2 as well?
Wei Li 2016/08/04 23:36:39 Yes, I think both patches share similar logic. Cou
Lei Zhang 2016/08/05 18:55:22 So CPDF_ImageObject::m_pImage gets assigned from 6
25 } 29 }
26 30
27 CPDF_ImageObject* CPDF_ImageObject::Clone() const { 31 CPDF_ImageObject* CPDF_ImageObject::Clone() const {
28 CPDF_ImageObject* obj = new CPDF_ImageObject; 32 CPDF_ImageObject* obj = new CPDF_ImageObject;
29 obj->CopyData(this); 33 obj->CopyData(this);
30 34
31 obj->m_pImage = m_pImage->Clone(); 35 obj->m_pImage = m_pImage->Clone();
32 obj->m_Matrix = m_Matrix; 36 obj->m_Matrix = m_Matrix;
33 return obj; 37 return obj;
34 } 38 }
(...skipping 17 matching lines...) Expand all
52 56
53 const CPDF_ImageObject* CPDF_ImageObject::AsImage() const { 57 const CPDF_ImageObject* CPDF_ImageObject::AsImage() const {
54 return this; 58 return this;
55 } 59 }
56 60
57 void CPDF_ImageObject::CalcBoundingBox() { 61 void CPDF_ImageObject::CalcBoundingBox() {
58 m_Left = m_Bottom = 0; 62 m_Left = m_Bottom = 0;
59 m_Right = m_Top = 1.0f; 63 m_Right = m_Top = 1.0f;
60 m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); 64 m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
61 } 65 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_image.cpp ('k') | core/fpdfapi/fpdf_page/fpdf_page_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698