From 4dce6d4689d464c3a8825a5d6aa790adfc9228ee Mon Sep 17 00:00:00 2001 From: thestig Date: Tue, 31 May 2016 05:46:52 -0700 Subject: Fix a leak in CXFA_FontMgr. Review-Url: https://codereview.chromium.org/2024713002 --- fpdfsdk/fpdfxfa/fpdfxfa_app.cpp | 3 ++- xfa/fxfa/app/xfa_ffapp.cpp | 10 ++++++---- xfa/fxfa/app/xfa_fontmgr.cpp | 11 ++++++----- xfa/fxfa/include/xfa_ffapp.h | 4 ++-- xfa/fxfa/include/xfa_fontmgr.h | 6 +++--- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp index 16efc0a1de..f7a6a3ba00 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp @@ -61,7 +61,8 @@ FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { return FALSE; m_pXFAApp = new CXFA_FFApp(this); - m_pXFAApp->SetDefaultFontMgr(new CXFA_DefFontMgr); + m_pXFAApp->SetDefaultFontMgr( + std::unique_ptr(new CXFA_DefFontMgr)); #endif return TRUE; } diff --git a/xfa/fxfa/app/xfa_ffapp.cpp b/xfa/fxfa/app/xfa_ffapp.cpp index 6b7c06dc21..a26e2c99cf 100644 --- a/xfa/fxfa/app/xfa_ffapp.cpp +++ b/xfa/fxfa/app/xfa_ffapp.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/include/xfa_ffapp.h" #include +#include #include "xfa/fgas/font/fgas_stdfontmgr.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" @@ -131,15 +132,16 @@ CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider, return pDoc; } -void CXFA_FFApp::SetDefaultFontMgr(CXFA_DefFontMgr* pFontMgr) { - if (!m_pFontMgr) { +void CXFA_FFApp::SetDefaultFontMgr(std::unique_ptr pFontMgr) { + if (!m_pFontMgr) m_pFontMgr = new CXFA_FontMgr(); - } - m_pFontMgr->SetDefFontMgr(pFontMgr); + m_pFontMgr->SetDefFontMgr(std::move(pFontMgr)); } + CXFA_FontMgr* CXFA_FFApp::GetXFAFontMgr() { return m_pFontMgr; } + IFX_FontMgr* CXFA_FFApp::GetFDEFontMgr() { if (!m_pFDEFontMgr) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ diff --git a/xfa/fxfa/app/xfa_fontmgr.cpp b/xfa/fxfa/app/xfa_fontmgr.cpp index 9fec265a5a..ae1449876f 100644 --- a/xfa/fxfa/app/xfa_fontmgr.cpp +++ b/xfa/fxfa/app/xfa_fontmgr.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/include/xfa_fontmgr.h" #include +#include #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" @@ -1997,7 +1998,7 @@ FX_BOOL CXFA_PDFFontMgr::GetCharWidth(IFX_Font* pFont, return TRUE; } -CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(nullptr) {} +CXFA_FontMgr::CXFA_FontMgr() {} CXFA_FontMgr::~CXFA_FontMgr() {} @@ -2023,9 +2024,9 @@ IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, if (pFont) return pFont; } - if (!pFont && m_pDefFontMgr) { + if (!pFont && m_pDefFontMgr) pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage); - } + if (!pFont && pMgr) { pPDFFont = nullptr; pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont, @@ -2056,6 +2057,6 @@ void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) { m_PDFFontMgrMap.erase(hDoc); } -void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) { - m_pDefFontMgr = pFontMgr; +void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr pFontMgr) { + m_pDefFontMgr = std::move(pFontMgr); } diff --git a/xfa/fxfa/include/xfa_ffapp.h b/xfa/fxfa/include/xfa_ffapp.h index c8df27da5b..191bb14174 100644 --- a/xfa/fxfa/include/xfa_ffapp.h +++ b/xfa/fxfa/include/xfa_ffapp.h @@ -36,7 +36,7 @@ class CXFA_FileRead : public IFX_FileRead { class CXFA_FFApp { public: - CXFA_FFApp(IXFA_AppProvider* pProvider); + explicit CXFA_FFApp(IXFA_AppProvider* pProvider); ~CXFA_FFApp(); CXFA_FFDocHandler* GetDocHandler(); @@ -45,7 +45,7 @@ class CXFA_FFApp { FX_BOOL bTakeOverFile); CXFA_FFDoc* CreateDoc(IXFA_DocProvider* pProvider, CPDF_Document* pPDFDoc); IXFA_AppProvider* GetAppProvider() { return m_pProvider; } - void SetDefaultFontMgr(CXFA_DefFontMgr* pFontMgr); + void SetDefaultFontMgr(std::unique_ptr pFontMgr); CXFA_FWLAdapterWidgetMgr* GetWidgetMgr(CFWL_WidgetMgrDelegate* pDelegate); IFWL_AdapterTimerMgr* GetTimerMgr(); diff --git a/xfa/fxfa/include/xfa_fontmgr.h b/xfa/fxfa/include/xfa_fontmgr.h index d2e731769a..ab59df94c6 100644 --- a/xfa/fxfa/include/xfa_fontmgr.h +++ b/xfa/fxfa/include/xfa_fontmgr.h @@ -45,7 +45,7 @@ class CXFA_DefFontMgr { class CXFA_PDFFontMgr { public: - CXFA_PDFFontMgr(CXFA_FFDoc* pDoc); + explicit CXFA_PDFFontMgr(CXFA_FFDoc* pDoc); ~CXFA_PDFFontMgr(); IFX_Font* GetFont(const CFX_WideStringC& wsFontFamily, @@ -88,10 +88,10 @@ class CXFA_FontMgr { uint16_t wCodePage = 0xFFFF); void LoadDocFonts(CXFA_FFDoc* hDoc); void ReleaseDocFonts(CXFA_FFDoc* hDoc); - void SetDefFontMgr(CXFA_DefFontMgr* pFontMgr); + void SetDefFontMgr(std::unique_ptr pFontMgr); protected: - CXFA_DefFontMgr* m_pDefFontMgr; + std::unique_ptr m_pDefFontMgr; std::map> m_PDFFontMgrMap; std::map m_FontMap; }; -- cgit v1.2.3