From dc006f9e436339adccc6b5c5bab09b77f518be04 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 26 Jun 2018 21:09:48 +0000 Subject: Use UnownedPtr<> in CPDF_Font Change-Id: I5dc72c48ffd50836dd8c6a21e23568bc8703ee5a Reviewed-on: https://pdfium-review.googlesource.com/36132 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- core/fpdfapi/font/cfx_stockfontarray.cpp | 6 ++++-- core/fpdfapi/font/cpdf_font.h | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/fpdfapi/font/cfx_stockfontarray.cpp b/core/fpdfapi/font/cfx_stockfontarray.cpp index 0808471c82..3b61e11f36 100644 --- a/core/fpdfapi/font/cfx_stockfontarray.cpp +++ b/core/fpdfapi/font/cfx_stockfontarray.cpp @@ -15,8 +15,10 @@ CFX_StockFontArray::CFX_StockFontArray() {} CFX_StockFontArray::~CFX_StockFontArray() { for (size_t i = 0; i < FX_ArraySize(m_StockFonts); ++i) { - if (m_StockFonts[i]) - delete m_StockFonts[i]->GetFontDict(); + if (m_StockFonts[i]) { + std::unique_ptr destroy(m_StockFonts[i]->GetFontDict()); + m_StockFonts[i]->ClearFontDict(); + } } } diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h index 4b099ae0d0..9580d1c36b 100644 --- a/core/fpdfapi/font/cpdf_font.h +++ b/core/fpdfapi/font/cpdf_font.h @@ -66,8 +66,8 @@ class CPDF_Font { ByteString GetBaseFont() const { return m_BaseFont; } CFX_SubstFont* GetSubstFont() const { return m_Font.GetSubstFont(); } bool IsEmbedded() const { return IsType3Font() || m_pFontFile != nullptr; } - const CPDF_Dictionary* GetFontDict() const { return m_pFontDict; } - CPDF_Dictionary* GetFontDict() { return m_pFontDict; } + CPDF_Dictionary* GetFontDict() const { return m_pFontDict.Get(); } + void ClearFontDict() { m_pFontDict = nullptr; } bool IsStandardFont() const; FXFT_Face GetFace() const { return m_Font.GetFace(); } void AppendChar(ByteString* str, uint32_t charcode) const; @@ -113,7 +113,7 @@ class CPDF_Font { std::vector> m_FontFallbacks; ByteString m_BaseFont; RetainPtr m_pFontFile; - CPDF_Dictionary* m_pFontDict; + UnownedPtr m_pFontDict; mutable std::unique_ptr m_pToUnicodeMap; mutable bool m_bToUnicodeLoaded; int m_Flags; -- cgit v1.2.3