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

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: nit 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 <memory>
10
9 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" 11 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
10 #include "core/fpdfapi/fpdf_page/pageint.h" 12 #include "core/fpdfapi/fpdf_page/pageint.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
12 14
13 CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {} 15 CPDF_ImageObject::CPDF_ImageObject()
16 : m_pImage(nullptr), m_pImageOwned(false) {}
14 17
15 CPDF_ImageObject::~CPDF_ImageObject() { 18 CPDF_ImageObject::~CPDF_ImageObject() {
16 if (!m_pImage) { 19 Release();
17 return;
18 }
19 if (m_pImage->IsInline() ||
20 (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) {
21 delete m_pImage;
22 } else {
23 m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream());
24 }
25 } 20 }
26 21
27 CPDF_ImageObject* CPDF_ImageObject::Clone() const { 22 CPDF_ImageObject* CPDF_ImageObject::Clone() const {
28 CPDF_ImageObject* obj = new CPDF_ImageObject; 23 CPDF_ImageObject* obj = new CPDF_ImageObject;
29 obj->CopyData(this); 24 obj->CopyData(this);
30 25
31 obj->m_pImage = m_pImage->Clone(); 26 obj->m_pImage = m_pImage->Clone();
32 obj->m_Matrix = m_Matrix; 27 obj->m_Matrix = m_Matrix;
33 return obj; 28 return obj;
34 } 29 }
(...skipping 17 matching lines...) Expand all
52 47
53 const CPDF_ImageObject* CPDF_ImageObject::AsImage() const { 48 const CPDF_ImageObject* CPDF_ImageObject::AsImage() const {
54 return this; 49 return this;
55 } 50 }
56 51
57 void CPDF_ImageObject::CalcBoundingBox() { 52 void CPDF_ImageObject::CalcBoundingBox() {
58 m_Left = m_Bottom = 0; 53 m_Left = m_Bottom = 0;
59 m_Right = m_Top = 1.0f; 54 m_Right = m_Top = 1.0f;
60 m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); 55 m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
61 } 56 }
57
58 void CPDF_ImageObject::SetOwnedImage(std::unique_ptr<CPDF_Image> pImage) {
59 Release();
60 m_pImage = pImage.release();
61 m_pImageOwned = true;
62 }
63
64 void CPDF_ImageObject::SetUnownedImage(CPDF_Image* pImage) {
65 Release();
66 m_pImage = pImage;
67 m_pImageOwned = false;
68 }
69
70 void CPDF_ImageObject::Release() {
71 if (m_pImageOwned) {
72 delete m_pImage;
73 m_pImage = nullptr;
74 m_pImageOwned = false;
75 return;
76 }
77
78 if (!m_pImage)
79 return;
80
81 CPDF_DocPageData* pPageData = m_pImage->GetDocument()->GetPageData();
82 pPageData->ReleaseImage(m_pImage->GetStream());
83 m_pImage = nullptr;
84 }
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