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

Unified Diff: core/fpdfapi/fpdf_page/cpdf_image.cpp

Issue 2194393002: Fix a leak with FPDFPageObj_NewImgeObj(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 5 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
Index: core/fpdfapi/fpdf_page/cpdf_image.cpp
diff --git a/core/fpdfapi/fpdf_page/cpdf_image.cpp b/core/fpdfapi/fpdf_page/cpdf_image.cpp
index 63e006fc06054935d2762479897fe97d1faa918e..04883dc37156bb8ec8bb60766f27de7d9f476bc7 100644
--- a/core/fpdfapi/fpdf_page/cpdf_image.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_image.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
+#include <memory>
+
#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fpdfapi/fpdf_parser/cpdf_boolean.h"
@@ -23,8 +25,12 @@ CPDF_Image::CPDF_Image(CPDF_Document* pDoc)
m_pMask(nullptr),
m_MatteColor(0),
m_pStream(nullptr),
- m_bInline(FALSE),
+ m_bInline(false),
m_pInlineDict(nullptr),
+ m_Height(0),
+ m_Width(0),
+ m_bIsMask(false),
+ m_bInterpolate(false),
m_pDocument(pDoc),
m_pOC(nullptr) {}
@@ -37,8 +43,12 @@ CPDF_Image::~CPDF_Image() {
}
}
+bool CPDF_Image::CanRelease() const {
+ return m_bInline || (m_pStream && m_pStream->GetObjNum() == 0);
+}
+
void CPDF_Image::Release() {
- if (m_bInline || (m_pStream && m_pStream->GetObjNum() == 0))
+ if (CanRelease())
delete this;
}
@@ -54,7 +64,7 @@ CPDF_Image* CPDF_Image::Clone() {
return pImage;
}
-FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream* pStream, FX_BOOL bInline) {
+void CPDF_Image::LoadImageF(CPDF_Stream* pStream, bool bInline) {
m_pStream = pStream;
if (m_bInline && m_pInlineDict) {
m_pInlineDict->Release();
@@ -62,16 +72,15 @@ FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream* pStream, FX_BOOL bInline) {
}
m_bInline = bInline;
CPDF_Dictionary* pDict = pStream->GetDict();
- if (m_bInline) {
+ if (m_bInline)
m_pInlineDict = ToDictionary(pDict->Clone());
- }
+
m_pOC = pDict->GetDictBy("OC");
m_bIsMask =
!pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask");
m_bInterpolate = pDict->GetIntegerBy("Interpolate");
m_Height = pDict->GetIntegerBy("Height");
m_Width = pDict->GetIntegerBy("Width");
- return TRUE;
}
CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {

Powered by Google App Engine
This is Rietveld 408576698