summaryrefslogtreecommitdiff
path: root/core/fxge
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-09-08 11:47:29 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-08 11:47:29 -0700
commitc29fc707b24b9528e41a242cfa298275708ffc76 (patch)
tree392dcb77aef5657b51a25a632435fcc9787bcc89 /core/fxge
parenta31da74cffa8c3ff919051cc49bc006aeb55d345 (diff)
downloadpdfium-c29fc707b24b9528e41a242cfa298275708ffc76.tar.xz
Fix memory management errors for font loading and copying
A few issues are fixed: --Change variable |m_bLogic| in CFX_Font to |m_bShallowCopy| to reflect its meaning better; --For a shallow copy of font, we must guarantee that the copied font will not be deleted until the shallow copy is deleted. So need to increase the src font's refcount when copying it; --The stream |m_pOwnedStream| needs to have matched new/delete These errors need to be fixed before we can properly delete all the fonts to address the leaks. BUG=pdfium:242 Review-Url: https://codereview.chromium.org/2322043002
Diffstat (limited to 'core/fxge')
-rw-r--r--core/fxge/ge/cfx_font.cpp8
-rw-r--r--core/fxge/include/fx_font.h4
2 files changed, 6 insertions, 6 deletions
diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp
index 4aefec8d43..3d2e6d6499 100644
--- a/core/fxge/ge/cfx_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -220,7 +220,7 @@ const uint8_t CFX_Font::s_WeightPow_SHIFTJIS[] = {
CFX_Font::CFX_Font()
:
#ifdef PDF_ENABLE_XFA
- m_bLogic(FALSE),
+ m_bShallowCopy(false),
m_pOwnedStream(nullptr),
#endif // PDF_ENABLE_XFA
m_Face(nullptr),
@@ -239,7 +239,7 @@ FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) {
if (!pFont)
return FALSE;
- m_bLogic = TRUE;
+ m_bShallowCopy = true;
if (pFont->m_pSubstFont) {
m_pSubstFont.reset(new CFX_SubstFont);
m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset;
@@ -268,7 +268,7 @@ FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) {
CFX_Font::~CFX_Font() {
#ifdef PDF_ENABLE_XFA
- if (m_bLogic) {
+ if (m_bShallowCopy) {
m_OtfFontData.DetachBuffer();
return;
}
@@ -285,7 +285,7 @@ CFX_Font::~CFX_Font() {
CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face);
}
#ifdef PDF_ENABLE_XFA
- FX_Free(m_pOwnedStream);
+ delete m_pOwnedStream;
#endif // PDF_ENABLE_XFA
FX_Free(m_pGsubData);
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && !defined _SKIA_SUPPORT_
diff --git a/core/fxge/include/fx_font.h b/core/fxge/include/fx_font.h
index cdde643770..a607f3e0d5 100644
--- a/core/fxge/include/fx_font.h
+++ b/core/fxge/include/fx_font.h
@@ -151,8 +151,8 @@ class CFX_Font {
#ifdef PDF_ENABLE_XFA
protected:
CFX_BinaryBuf m_OtfFontData;
- FX_BOOL m_bLogic;
- void* m_pOwnedStream;
+ bool m_bShallowCopy;
+ FXFT_StreamRec* m_pOwnedStream;
#endif // PDF_ENABLE_XFA
private: