Use UnownedPtr<> in CPDF_Font

Change-Id: I5dc72c48ffd50836dd8c6a21e23568bc8703ee5a
Reviewed-on: https://pdfium-review.googlesource.com/36132
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cfx_stockfontarray.cpp b/core/fpdfapi/font/cfx_stockfontarray.cpp
index 0808471..3b61e11 100644
--- a/core/fpdfapi/font/cfx_stockfontarray.cpp
+++ b/core/fpdfapi/font/cfx_stockfontarray.cpp
@@ -15,8 +15,10 @@
 
 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<CPDF_Dictionary> 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 4b099ae..9580d1c 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -66,8 +66,8 @@
   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 @@
   std::vector<std::unique_ptr<CFX_Font>> m_FontFallbacks;
   ByteString m_BaseFont;
   RetainPtr<CPDF_StreamAcc> m_pFontFile;
-  CPDF_Dictionary* m_pFontDict;
+  UnownedPtr<CPDF_Dictionary> m_pFontDict;
   mutable std::unique_ptr<CPDF_ToUnicodeMap> m_pToUnicodeMap;
   mutable bool m_bToUnicodeLoaded;
   int m_Flags;