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

Unified Diff: xfa/fgas/font/fgas_gefont.cpp

Issue 2322043002: Fix memory management errors for font loading and copying (Closed)
Patch Set: address comments Created 4 years, 3 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 | « xfa/fgas/font/fgas_gefont.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: xfa/fgas/font/fgas_gefont.cpp
diff --git a/xfa/fgas/font/fgas_gefont.cpp b/xfa/fgas/font/fgas_gefont.cpp
index 1507fa4840a22c21e6ff185c22d390490ae77554..d3be9dcb48a44ac17de9d0651c0a680b30112304 100644
--- a/xfa/fgas/font/fgas_gefont.cpp
+++ b/xfa/fgas/font/fgas_gefont.cpp
@@ -77,26 +77,29 @@ CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr)
m_dwLogFontStyle(0),
#endif
m_pFont(nullptr),
+ m_pSrcFont(nullptr),
m_pFontMgr(pFontMgr),
m_iRefCount(1),
m_bExtFont(FALSE),
m_pProvider(nullptr) {
}
-CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles)
+CFGAS_GEFont::CFGAS_GEFont(CFGAS_GEFont* src, uint32_t dwFontStyles)
:
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
m_bUseLogFontStyle(FALSE),
m_dwLogFontStyle(0),
#endif
m_pFont(nullptr),
- m_pFontMgr(src.m_pFontMgr),
+ m_pSrcFont(src),
+ m_pFontMgr(src->m_pFontMgr),
m_iRefCount(1),
m_bExtFont(FALSE),
m_pProvider(nullptr) {
- ASSERT(src.m_pFont);
+ ASSERT(m_pSrcFont->m_pFont);
+ m_pSrcFont->Retain();
m_pFont = new CFX_Font;
- m_pFont->LoadClone(src.m_pFont);
+ m_pFont->LoadClone(m_pSrcFont->m_pFont);
CFX_SubstFont* pSubst = m_pFont->GetSubstFont();
if (!pSubst) {
pSubst = new CFX_SubstFont;
@@ -119,6 +122,11 @@ CFGAS_GEFont::~CFGAS_GEFont() {
if (!m_bExtFont)
delete m_pFont;
+
+ // If it is a shallow copy of another source font,
+ // decrease the refcount of the source font.
+ if (m_pSrcFont)
+ m_pSrcFont->Release();
}
void CFGAS_GEFont::Release() {
@@ -239,7 +247,7 @@ FX_BOOL CFGAS_GEFont::InitFont() {
CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) {
if (GetFontStyles() == dwFontStyles)
return Retain();
- return new CFGAS_GEFont(*this, dwFontStyles);
+ return new CFGAS_GEFont(this, dwFontStyles);
}
void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const {
« no previous file with comments | « xfa/fgas/font/fgas_gefont.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698