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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_page/cpdf_imageobject.cpp
diff --git a/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp b/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp
index e2defa80544be13b50a30babfe498ed7edae4a4e..1fa14805aad340d0ae975aff9dd93c8b424a7bcf 100644
--- a/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp
@@ -6,22 +6,17 @@
#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h"
+#include <memory>
+
#include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
-CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {}
+CPDF_ImageObject::CPDF_ImageObject()
+ : m_pImage(nullptr), m_pImageOwned(false) {}
CPDF_ImageObject::~CPDF_ImageObject() {
- if (!m_pImage) {
- return;
- }
- if (m_pImage->IsInline() ||
- (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) {
- delete m_pImage;
- } else {
- m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream());
- }
+ Release();
}
CPDF_ImageObject* CPDF_ImageObject::Clone() const {
@@ -59,3 +54,31 @@ void CPDF_ImageObject::CalcBoundingBox() {
m_Right = m_Top = 1.0f;
m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
}
+
+void CPDF_ImageObject::SetOwnedImage(std::unique_ptr<CPDF_Image> pImage) {
+ Release();
+ m_pImage = pImage.release();
+ m_pImageOwned = true;
+}
+
+void CPDF_ImageObject::SetUnownedImage(CPDF_Image* pImage) {
+ Release();
+ m_pImage = pImage;
+ m_pImageOwned = false;
+}
+
+void CPDF_ImageObject::Release() {
+ if (m_pImageOwned) {
+ delete m_pImage;
+ m_pImage = nullptr;
+ m_pImageOwned = false;
+ return;
+ }
+
+ if (!m_pImage)
+ return;
+
+ CPDF_DocPageData* pPageData = m_pImage->GetDocument()->GetPageData();
+ pPageData->ReleaseImage(m_pImage->GetStream());
+ m_pImage = nullptr;
+}
« 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