From a9d29df6a774737a661d0f37f6b8aa5cba179c06 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 7 Dec 2016 15:28:14 -0800 Subject: Properly ref count IFX_FileAccess. Review-Url: https://codereview.chromium.org/2562563002 --- xfa/fgas/font/cfgas_fontmgr.cpp | 23 ++++++++++------------- xfa/fgas/font/cfgas_fontmgr.h | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'xfa/fgas') diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 060dd95b48..d7e7e8ed84 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -566,10 +566,12 @@ FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() { return (FX_POSITION)-1; } -IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { - IFX_FileAccess* pAccess = IFX_FileAccess::CreateDefault(m_wsNext.AsStringC()); +CFX_RetainPtr CFX_FontSourceEnum_File::GetNext( + FX_POSITION& pos) { + CFX_RetainPtr pAccess = + IFX_FileAccess::CreateDefault(m_wsNext.AsStringC()); m_wsNext = GetNextFile().UTF8Decode(); - pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr; + pos = m_wsNext.GetLength() != 0 ? pAccess.Get() : nullptr; return pAccess; } @@ -636,17 +638,12 @@ bool CFGAS_FontMgr::EnumFontsFromFontMapper() { bool CFGAS_FontMgr::EnumFontsFromFiles() { CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); FX_POSITION pos = m_pFontSource->GetStartPosition(); - IFX_FileAccess* pFontSource = nullptr; - CFX_RetainPtr pFontStream; while (pos) { - pFontSource = m_pFontSource->GetNext(pos); - pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); - if (!pFontStream) { - pFontSource->Release(); - continue; - } - RegisterFaces(pFontStream, nullptr); - pFontSource->Release(); + CFX_RetainPtr pFontSource = m_pFontSource->GetNext(pos); + CFX_RetainPtr pFontStream = + pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); + if (pFontStream) + RegisterFaces(pFontStream, nullptr); } return m_InstalledFonts.GetSize() != 0; } diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index 28a8bb528a..d3eb8f1a85 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -179,7 +179,7 @@ class CFX_FontSourceEnum_File { ~CFX_FontSourceEnum_File(); FX_POSITION GetStartPosition(); - IFX_FileAccess* GetNext(FX_POSITION& pos); + CFX_RetainPtr GetNext(FX_POSITION& pos); private: CFX_ByteString GetNextFile(); -- cgit v1.2.3