From 365333552cf67b7c97c4093177e7ed7b43f540ab Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 16 May 2017 15:40:23 -0700 Subject: CFDE_RenderDevice::m_bOwnerDevice is always false So remove it. But they probably wanted it to be true in one place, because it looks like a leak. So find a better way to own the object. Change-Id: I15937e29da5ce8b380f82cb20ee3ecc3f49b8ca3 Reviewed-on: https://pdfium-review.googlesource.com/5473 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- xfa/fde/cfde_renderdevice.cpp | 10 +++------- xfa/fde/cfde_renderdevice.h | 3 +-- xfa/fde/cfde_textout.cpp | 11 ++++++----- xfa/fde/cfde_textout.h | 2 ++ 4 files changed, 12 insertions(+), 14 deletions(-) (limited to 'xfa/fde') diff --git a/xfa/fde/cfde_renderdevice.cpp b/xfa/fde/cfde_renderdevice.cpp index 7fb5b0352e..9236dc7800 100644 --- a/xfa/fde/cfde_renderdevice.cpp +++ b/xfa/fde/cfde_renderdevice.cpp @@ -22,9 +22,8 @@ #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fgas/font/cfgas_gefont.h" -CFDE_RenderDevice::CFDE_RenderDevice(CFX_RenderDevice* pDevice, - bool bOwnerDevice) - : m_pDevice(pDevice), m_bOwnerDevice(bOwnerDevice), m_iCharCount(0) { +CFDE_RenderDevice::CFDE_RenderDevice(CFX_RenderDevice* pDevice) + : m_pDevice(pDevice), m_iCharCount(0) { ASSERT(pDevice); FX_RECT rt = m_pDevice->GetClipBox(); @@ -33,10 +32,7 @@ CFDE_RenderDevice::CFDE_RenderDevice(CFX_RenderDevice* pDevice, static_cast(rt.Height())); } -CFDE_RenderDevice::~CFDE_RenderDevice() { - if (m_bOwnerDevice) - delete m_pDevice; -} +CFDE_RenderDevice::~CFDE_RenderDevice() {} int32_t CFDE_RenderDevice::GetWidth() const { return m_pDevice->GetWidth(); diff --git a/xfa/fde/cfde_renderdevice.h b/xfa/fde/cfde_renderdevice.h index f429ac1703..d9f4ce0d34 100644 --- a/xfa/fde/cfde_renderdevice.h +++ b/xfa/fde/cfde_renderdevice.h @@ -19,7 +19,7 @@ class CFX_GraphStateData; class CFDE_RenderDevice { public: - CFDE_RenderDevice(CFX_RenderDevice* pDevice, bool bOwnerDevice); + explicit CFDE_RenderDevice(CFX_RenderDevice* pDevice); ~CFDE_RenderDevice(); int32_t GetWidth() const; @@ -120,7 +120,6 @@ class CFDE_RenderDevice { CFX_RenderDevice* const m_pDevice; CFX_RectF m_rtClip; - bool m_bOwnerDevice; int32_t m_iCharCount; }; diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp index b41ee1fbd8..6d5ab2a980 100644 --- a/xfa/fde/cfde_textout.cpp +++ b/xfa/fde/cfde_textout.cpp @@ -7,6 +7,7 @@ #include "xfa/fde/cfde_textout.h" #include +#include #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" @@ -117,16 +118,16 @@ void CFDE_TextOut::SetLineSpace(float fLineSpace) { void CFDE_TextOut::SetDIBitmap(const CFX_RetainPtr& pDIB) { ASSERT(pDIB); - m_pRenderDevice.reset(); - CFX_DefaultRenderDevice* device = new CFX_DefaultRenderDevice; - device->Attach(pDIB, false, nullptr, false); - m_pRenderDevice = pdfium::MakeUnique(device, false); + m_pDefaultRenderDevice = pdfium::MakeUnique(); + m_pDefaultRenderDevice->Attach(pDIB, false, nullptr, false); + m_pRenderDevice = + pdfium::MakeUnique(m_pDefaultRenderDevice.get()); } void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { ASSERT(pDevice); - m_pRenderDevice = pdfium::MakeUnique(pDevice, false); + m_pRenderDevice = pdfium::MakeUnique(pDevice); } void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h index 360c3051e9..a52814041b 100644 --- a/xfa/fde/cfde_textout.h +++ b/xfa/fde/cfde_textout.h @@ -167,6 +167,8 @@ class CFDE_TextOut { int32_t m_iCurPiece; int32_t m_iTotalLines; std::vector m_CharPos; + // NOTE: m_pDefaultRenderDevice must outlive m_pRenderDevice. + std::unique_ptr m_pDefaultRenderDevice; std::unique_ptr m_pRenderDevice; std::vector m_HotKeys; std::vector m_rectArray; -- cgit v1.2.3