Mass conversion of remaining class members (non-xfa)

Change-Id: I8365ba80e3395d59a3cf35dbd9d9162e86e712e3
Reviewed-on: https://pdfium-review.googlesource.com/5970
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/cmaps/fpdf_cmaps.cpp b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
index cb2f09f..13aec26 100644
--- a/core/fpdfapi/cmaps/fpdf_cmaps.cpp
+++ b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
@@ -61,7 +61,7 @@
   CPDF_FontGlobals* pFontGlobals =
       CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
   const FXCMAP_CMap* pCMaps =
-      pFontGlobals->m_EmbeddedCharsets[charset].m_pMapList;
+      pFontGlobals->m_EmbeddedCharsets[charset].m_pMapList.Get();
   for (uint32_t i = 0; i < pFontGlobals->m_EmbeddedCharsets[charset].m_Count;
        i++) {
     if (bsName == pCMaps[i].m_Name) {
diff --git a/core/fpdfapi/font/font_int.h b/core/fpdfapi/font/font_int.h
index ebd08e2..5544a1b 100644
--- a/core/fpdfapi/font/font_int.h
+++ b/core/fpdfapi/font/font_int.h
@@ -14,6 +14,7 @@
 
 #include "core/fpdfapi/font/cpdf_cidfont.h"
 #include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 
 class CPDF_CID2UnicodeMap;
@@ -194,7 +195,7 @@
   uint32_t GetUnicode();
 
   std::map<uint32_t, uint32_t> m_Map;
-  CPDF_CID2UnicodeMap* m_pBaseMap;
+  CFX_UnownedPtr<CPDF_CID2UnicodeMap> m_pBaseMap;
   CFX_WideTextBuf m_MultiCharBuf;
 };
 
@@ -213,7 +214,7 @@
 
   CPDF_CMapManager m_CMapManager;
   struct {
-    const FXCMAP_CMap* m_pMapList;
+    CFX_UnownedPtr<const FXCMAP_CMap> m_pMapList;
     uint32_t m_Count;
   } m_EmbeddedCharsets[CIDSET_NUM_SETS];
   struct {
diff --git a/core/fpdfapi/page/cpdf_color.cpp b/core/fpdfapi/page/cpdf_color.cpp
index e6665c8..747e684 100644
--- a/core/fpdfapi/page/cpdf_color.cpp
+++ b/core/fpdfapi/page/cpdf_color.cpp
@@ -160,6 +160,6 @@
   if (!m_pBuffer || m_pCS->GetFamily() != PDFCS_PATTERN)
     return nullptr;
 
-  PatternValue* pvalue = (PatternValue*)m_pBuffer;
+  PatternValue* pvalue = reinterpret_cast<PatternValue*>(m_pBuffer);
   return pvalue->m_pPattern;
 }
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 345180f..90ef894 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -190,7 +190,7 @@
   void EnableStdConversion(bool bEnabled) override;
 
   CPDF_ColorSpace* m_pBaseCS;
-  CPDF_CountedColorSpace* m_pCountedBaseCS;
+  CFX_UnownedPtr<CPDF_CountedColorSpace> m_pCountedBaseCS;
   int m_nBaseComponents;
   int m_MaxIndex;
   CFX_ByteString m_Table;
diff --git a/core/fpdfapi/page/cpdf_shadingobject.h b/core/fpdfapi/page/cpdf_shadingobject.h
index ffd6223..9db6712 100644
--- a/core/fpdfapi/page/cpdf_shadingobject.h
+++ b/core/fpdfapi/page/cpdf_shadingobject.h
@@ -8,6 +8,7 @@
 #define CORE_FPDFAPI_PAGE_CPDF_SHADINGOBJECT_H_
 
 #include "core/fpdfapi/page/cpdf_pageobject.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 
 class CPDF_ShadingPattern;
@@ -26,7 +27,7 @@
 
   void CalcBoundingBox();
 
-  CPDF_ShadingPattern* m_pShading;
+  CFX_UnownedPtr<CPDF_ShadingPattern> m_pShading;
   CFX_Matrix m_Matrix;
 };
 
diff --git a/core/fpdfapi/page/cpdf_shadingpattern.h b/core/fpdfapi/page/cpdf_shadingpattern.h
index 068d772..24ad4c2 100644
--- a/core/fpdfapi/page/cpdf_shadingpattern.h
+++ b/core/fpdfapi/page/cpdf_shadingpattern.h
@@ -55,7 +55,7 @@
   ShadingType GetShadingType() const { return m_ShadingType; }
   bool IsShadingObject() const { return m_bShadingObj; }
   CPDF_Object* GetShadingObject() const { return m_pShadingObj.Get(); }
-  CPDF_ColorSpace* GetCS() const { return m_pCS; }
+  CPDF_ColorSpace* GetCS() const { return m_pCS.Get(); }
   const std::vector<std::unique_ptr<CPDF_Function>>& GetFuncs() const {
     return m_pFunctions;
   }
@@ -67,9 +67,9 @@
 
   // Still keep |m_pCS| as some CPDF_ColorSpace (name object) are not managed
   // as counted objects. Refer to CPDF_DocPageData::GetColorSpace.
-  CPDF_ColorSpace* m_pCS;
+  CFX_UnownedPtr<CPDF_ColorSpace> m_pCS;
 
-  CPDF_CountedColorSpace* m_pCountedCS;
+  CFX_UnownedPtr<CPDF_CountedColorSpace> m_pCountedCS;
   std::vector<std::unique_ptr<CPDF_Function>> m_pFunctions;
 };
 
diff --git a/core/fpdfapi/parser/cfdf_document.h b/core/fpdfapi/parser/cfdf_document.h
index f83adc1..9a13877 100644
--- a/core/fpdfapi/parser/cfdf_document.h
+++ b/core/fpdfapi/parser/cfdf_document.h
@@ -11,6 +11,7 @@
 
 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
 #include "core/fpdfapi/parser/cpdf_object.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 
 class CPDF_Dictionary;
@@ -27,12 +28,12 @@
   ~CFDF_Document() override;
 
   bool WriteBuf(CFX_ByteTextBuf& buf) const;
-  CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
+  CPDF_Dictionary* GetRoot() const { return m_pRootDict.Get(); }
 
  protected:
   void ParseStream(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
 
-  CPDF_Dictionary* m_pRootDict;
+  CFX_UnownedPtr<CPDF_Dictionary> m_pRootDict;
   CFX_RetainPtr<IFX_SeekableReadStream> m_pFile;
 };
 
diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h
index 8edf062..f47c859 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.h
+++ b/core/fpdfapi/parser/cpdf_data_avail.h
@@ -13,6 +13,7 @@
 
 #include "core/fpdfapi/parser/cpdf_parser.h"
 #include "core/fpdfapi/parser/cpdf_syntax_parser.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 
 class CPDF_Dictionary;
@@ -204,7 +205,7 @@
   uint32_t m_dwRootObjNum;
   uint32_t m_dwInfoObjNum;
   std::unique_ptr<CPDF_LinearizedHeader> m_pLinearized;
-  CPDF_Object* m_pTrailer;
+  CFX_UnownedPtr<CPDF_Object> m_pTrailer;
   bool m_bDocAvail;
   FX_FILESIZE m_dwHeaderOffset;
   FX_FILESIZE m_dwLastXRefOffset;
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 1923992..24a9896 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -82,7 +82,7 @@
     // All direct objects.
     CPDF_Object* objs[] = {boolean_false_obj, boolean_true_obj, number_int_obj,
                            number_float_obj,  str_reg_obj,      str_spec_obj,
-                           name_obj,          m_ArrayObj,       m_DictObj,
+                           name_obj,          m_ArrayObj.Get(), m_DictObj.Get(),
                            stream_obj,        null_obj};
     m_DirectObjTypes = {
         CPDF_Object::BOOLEAN, CPDF_Object::BOOLEAN, CPDF_Object::NUMBER,
@@ -179,9 +179,9 @@
   std::vector<std::unique_ptr<CPDF_Object>> m_DirectObjs;
   std::vector<int> m_DirectObjTypes;
   std::vector<std::unique_ptr<CPDF_Object>> m_RefObjs;
-  CPDF_Dictionary* m_DictObj;
-  CPDF_Dictionary* m_StreamDictObj;
-  CPDF_Array* m_ArrayObj;
+  CFX_UnownedPtr<CPDF_Dictionary> m_DictObj;
+  CFX_UnownedPtr<CPDF_Dictionary> m_StreamDictObj;
+  CFX_UnownedPtr<CPDF_Array> m_ArrayObj;
   std::vector<CPDF_Object*> m_IndirectObjs;
 };
 
@@ -244,23 +244,29 @@
 
 TEST_F(PDFObjectsTest, GetDict) {
   const CPDF_Dictionary* const direct_obj_results[] = {
-      nullptr, nullptr, nullptr,   nullptr,         nullptr, nullptr,
-      nullptr, nullptr, m_DictObj, m_StreamDictObj, nullptr};
+      nullptr, nullptr, nullptr, nullptr,         nullptr,
+      nullptr, nullptr, nullptr, m_DictObj.Get(), m_StreamDictObj.Get(),
+      nullptr};
   // Check for direct objects.
   for (size_t i = 0; i < m_DirectObjs.size(); ++i)
     EXPECT_EQ(direct_obj_results[i], m_DirectObjs[i]->GetDict());
 
   // Check indirect references.
-  const CPDF_Dictionary* const indirect_obj_results[] = {
-      nullptr, nullptr, nullptr, nullptr, nullptr, m_DictObj, m_StreamDictObj};
+  const CPDF_Dictionary* const indirect_obj_results[] = {nullptr,
+                                                         nullptr,
+                                                         nullptr,
+                                                         nullptr,
+                                                         nullptr,
+                                                         m_DictObj.Get(),
+                                                         m_StreamDictObj.Get()};
   for (size_t i = 0; i < m_RefObjs.size(); ++i)
     EXPECT_TRUE(Equal(indirect_obj_results[i], m_RefObjs[i]->GetDict()));
 }
 
 TEST_F(PDFObjectsTest, GetArray) {
   const CPDF_Array* const direct_obj_results[] = {
-      nullptr, nullptr,    nullptr, nullptr, nullptr, nullptr,
-      nullptr, m_ArrayObj, nullptr, nullptr, nullptr};
+      nullptr, nullptr,          nullptr, nullptr, nullptr, nullptr,
+      nullptr, m_ArrayObj.Get(), nullptr, nullptr, nullptr};
   // Check for direct objects.
   for (size_t i = 0; i < m_DirectObjs.size(); ++i)
     EXPECT_EQ(direct_obj_results[i], m_DirectObjs[i]->AsArray());
diff --git a/core/fpdfapi/render/cpdf_imageloader.cpp b/core/fpdfapi/render/cpdf_imageloader.cpp
index 53b6009..b09b919 100644
--- a/core/fpdfapi/render/cpdf_imageloader.cpp
+++ b/core/fpdfapi/render/cpdf_imageloader.cpp
@@ -36,8 +36,8 @@
                                        GroupFamily, bLoadMask, pRenderStatus);
   } else {
     ret = m_pImageObject->GetImage()->StartLoadDIBSource(
-        pRenderStatus->m_pFormResource, pRenderStatus->m_pPageResource, bStdCS,
-        GroupFamily, bLoadMask);
+        pRenderStatus->m_pFormResource.Get(),
+        pRenderStatus->m_pPageResource.Get(), bStdCS, GroupFamily, bLoadMask);
   }
   if (!ret)
     HandleFailure();
diff --git a/core/fpdfapi/render/cpdf_imageloader.h b/core/fpdfapi/render/cpdf_imageloader.h
index f17f29c..47dd2f9 100644
--- a/core/fpdfapi/render/cpdf_imageloader.h
+++ b/core/fpdfapi/render/cpdf_imageloader.h
@@ -9,6 +9,7 @@
 
 #include <memory>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 #include "core/fxge/fx_dib.h"
 
@@ -37,8 +38,8 @@
  private:
   void HandleFailure();
 
-  CPDF_PageRenderCache* m_pCache;
-  CPDF_ImageObject* m_pImageObject;
+  CFX_UnownedPtr<CPDF_PageRenderCache> m_pCache;
+  CFX_UnownedPtr<CPDF_ImageObject> m_pImageObject;
 };
 
 #endif  // CORE_FPDFAPI_RENDER_CPDF_IMAGELOADER_H_
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index ff4ed9c..716203a 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -225,8 +225,8 @@
     CFX_Matrix* pNewMatrix,
     const FX_RECT& rect) const {
   CPDF_RenderStatus bitmap_render;
-  bitmap_render.Initialize(m_pRenderStatus->m_pContext, pBitmapDevice2, nullptr,
-                           nullptr, nullptr, nullptr, nullptr, 0,
+  bitmap_render.Initialize(m_pRenderStatus->m_pContext.Get(), pBitmapDevice2,
+                           nullptr, nullptr, nullptr, nullptr, nullptr, 0,
                            m_pRenderStatus->m_bDropObjects, nullptr, true);
   CPDF_ImageRenderer image_render;
   if (image_render.Start(&bitmap_render, pDIBSource, 0xffffffff, 255,
@@ -276,7 +276,7 @@
 
   bitmap_device1.GetBitmap()->Clear(0xffffff);
   CPDF_RenderStatus bitmap_render;
-  bitmap_render.Initialize(m_pRenderStatus->m_pContext, &bitmap_device1,
+  bitmap_render.Initialize(m_pRenderStatus->m_pContext.Get(), &bitmap_device1,
                            nullptr, nullptr, nullptr, nullptr,
                            &m_pRenderStatus->m_Options, 0,
                            m_pRenderStatus->m_bDropObjects, nullptr, true);
@@ -329,7 +329,7 @@
   bitmap_device1.GetBitmap()->Clear(0xffffff);
 #endif
   CPDF_RenderStatus bitmap_render;
-  bitmap_render.Initialize(m_pRenderStatus->m_pContext, &bitmap_device1,
+  bitmap_render.Initialize(m_pRenderStatus->m_pContext.Get(), &bitmap_device1,
                            nullptr, nullptr, nullptr, nullptr, nullptr, 0,
                            m_pRenderStatus->m_bDropObjects, nullptr, true);
   CPDF_ImageRenderer image_render;
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.h b/core/fpdfapi/render/cpdf_imagerenderer.h
index bf73098..4615928 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.h
+++ b/core/fpdfapi/render/cpdf_imagerenderer.h
@@ -10,6 +10,7 @@
 #include <memory>
 
 #include "core/fpdfapi/render/cpdf_imageloader.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxge/dib/cfx_imagerenderer.h"
 
@@ -72,7 +73,7 @@
   CFX_RetainPtr<CFX_DIBitmap> m_pClone;
   int m_BitmapAlpha;
   bool m_bPatternColor;
-  CPDF_Pattern* m_pPattern;
+  CFX_UnownedPtr<CPDF_Pattern> m_pPattern;
   FX_ARGB m_FillArgb;
   uint32_t m_Flags;
   std::unique_ptr<CFX_ImageTransformer> m_pTransformer;
diff --git a/core/fpdfapi/render/cpdf_pagerendercache.cpp b/core/fpdfapi/render/cpdf_pagerendercache.cpp
index a997e34..455b7f5 100644
--- a/core/fpdfapi/render/cpdf_pagerendercache.cpp
+++ b/core/fpdfapi/render/cpdf_pagerendercache.cpp
@@ -95,8 +95,8 @@
         new CPDF_ImageCacheEntry(m_pPage->m_pDocument.Get(), pImage);
   }
   int ret = m_pCurImageCacheEntry->StartGetCachedBitmap(
-      pRenderStatus->m_pFormResource, m_pPage->m_pPageResources.Get(), bStdCS,
-      GroupFamily, bLoadMask, pRenderStatus);
+      pRenderStatus->m_pFormResource.Get(), m_pPage->m_pPageResources.Get(),
+      bStdCS, GroupFamily, bLoadMask, pRenderStatus);
   if (ret == 2)
     return true;
 
diff --git a/core/fpdfapi/render/cpdf_rendercontext.cpp b/core/fpdfapi/render/cpdf_rendercontext.cpp
index 2cd59ca..dec5132 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.cpp
+++ b/core/fpdfapi/render/cpdf_rendercontext.cpp
@@ -72,12 +72,12 @@
       status.Initialize(this, pDevice, pLastMatrix, pStopObj, nullptr, nullptr,
                         pOptions, layer.m_pObjectHolder->m_Transparency, false,
                         nullptr);
-      status.RenderObjectList(layer.m_pObjectHolder, &FinalMatrix);
+      status.RenderObjectList(layer.m_pObjectHolder.Get(), &FinalMatrix);
     } else {
       status.Initialize(this, pDevice, nullptr, pStopObj, nullptr, nullptr,
                         pOptions, layer.m_pObjectHolder->m_Transparency, false,
                         nullptr);
-      status.RenderObjectList(layer.m_pObjectHolder, &layer.m_Matrix);
+      status.RenderObjectList(layer.m_pObjectHolder.Get(), &layer.m_Matrix);
     }
     if (status.m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE)
       m_pPageCache->CacheOptimization(status.m_Options.m_dwLimitCacheSize);
@@ -85,3 +85,9 @@
       break;
   }
 }
+
+CPDF_RenderContext::Layer::Layer() {}
+
+CPDF_RenderContext::Layer::Layer(const Layer& that) = default;
+
+CPDF_RenderContext::Layer::~Layer() {}
diff --git a/core/fpdfapi/render/cpdf_rendercontext.h b/core/fpdfapi/render/cpdf_rendercontext.h
index 4980d37..220ff2b 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.h
+++ b/core/fpdfapi/render/cpdf_rendercontext.h
@@ -9,6 +9,7 @@
 
 #include <vector>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 #include "core/fxcrt/fx_coordinates.h"
 
@@ -27,7 +28,11 @@
  public:
   class Layer {
    public:
-    CPDF_PageObjectHolder* m_pObjectHolder;
+    Layer();
+    Layer(const Layer& that);
+    ~Layer();
+
+    CFX_UnownedPtr<CPDF_PageObjectHolder> m_pObjectHolder;
     CFX_Matrix m_Matrix;
   };
 
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 7c17ff5..beeca3f 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1235,7 +1235,8 @@
     res = 0;
   }
   CPDF_ScaledRenderBuffer buffer;
-  if (!buffer.Initialize(m_pContext, m_pDevice, rect, pObj, &m_Options, res)) {
+  if (!buffer.Initialize(m_pContext.Get(), m_pDevice, rect, pObj, &m_Options,
+                         res)) {
     return;
   }
   CFX_Matrix matrix = *pObj2Device;
@@ -1249,8 +1250,8 @@
     }
   }
   CPDF_RenderStatus status;
-  status.Initialize(m_pContext, buffer.GetDevice(), buffer.GetMatrix(), nullptr,
-                    nullptr, nullptr, &m_Options, m_Transparency,
+  status.Initialize(m_pContext.Get(), buffer.GetDevice(), buffer.GetMatrix(),
+                    nullptr, nullptr, nullptr, &m_Options, m_Transparency,
                     m_bDropObjects, pFormResource);
   status.RenderSingleObject(pObj, &matrix);
   buffer.OutputToDevice();
@@ -1273,9 +1274,9 @@
     pResources = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources");
   }
   CPDF_RenderStatus status;
-  status.Initialize(m_pContext, m_pDevice, nullptr, m_pStopObj, this, pFormObj,
-                    &m_Options, m_Transparency, m_bDropObjects, pResources,
-                    false);
+  status.Initialize(m_pContext.Get(), m_pDevice, nullptr, m_pStopObj, this,
+                    pFormObj, &m_Options, m_Transparency, m_bDropObjects,
+                    pResources, false);
   status.m_curBlend = m_curBlend;
   {
     CFX_RenderDevice::StateRestorer restorer(m_pDevice);
@@ -1605,9 +1606,9 @@
     }
   }
   CPDF_RenderStatus bitmap_render;
-  bitmap_render.Initialize(m_pContext, &bitmap_device, nullptr, m_pStopObj,
-                           nullptr, nullptr, &m_Options, 0, m_bDropObjects,
-                           pFormResource, true);
+  bitmap_render.Initialize(m_pContext.Get(), &bitmap_device, nullptr,
+                           m_pStopObj, nullptr, nullptr, &m_Options, 0,
+                           m_bDropObjects, pFormResource, true);
   bitmap_render.ProcessObjectNoClip(pPageObj, &new_matrix);
 #if defined _SKIA_SUPPORT_PATHS_
   bitmap_device.Flush();
@@ -1871,7 +1872,7 @@
     matrix.e += iChar ? textobj->m_CharPos[iChar - 1] : 0;
     matrix.Concat(text_matrix);
     matrix.Concat(*pObj2Device);
-    if (!pType3Char->LoadBitmap(m_pContext)) {
+    if (!pType3Char->LoadBitmap(m_pContext.Get())) {
       if (!glyphs.empty()) {
         for (int i = 0; i < iChar; i++) {
           const FXTEXT_GLYPHPOS& glyph = glyphs[i];
@@ -1897,7 +1898,7 @@
       }
       if (fill_alpha == 255) {
         CPDF_RenderStatus status;
-        status.Initialize(m_pContext, m_pDevice, nullptr, nullptr, this,
+        status.Initialize(m_pContext.Get(), m_pDevice, nullptr, nullptr, this,
                           pStates.get(), &Options,
                           pType3Char->m_pForm->m_Transparency, m_bDropObjects,
                           pFormResource, false, pType3Char, fill_argb);
@@ -1919,8 +1920,8 @@
         }
         bitmap_device.GetBitmap()->Clear(0);
         CPDF_RenderStatus status;
-        status.Initialize(m_pContext, &bitmap_device, nullptr, nullptr, this,
-                          pStates.get(), &Options,
+        status.Initialize(m_pContext.Get(), &bitmap_device, nullptr, nullptr,
+                          this, pStates.get(), &Options,
                           pType3Char->m_pForm->m_Transparency, m_bDropObjects,
                           pFormResource, false, pType3Char, fill_argb);
         status.m_Type3FontCache = m_Type3FontCache;
@@ -2093,7 +2094,7 @@
     return;
   }
   CPDF_DeviceBuffer buffer;
-  buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150);
+  buffer.Initialize(m_pContext.Get(), m_pDevice, &clip_rect, m_pCurObj, 150);
   CFX_Matrix FinalMatrix = *pMatrix;
   FinalMatrix.Concat(*buffer.GetMatrix());
   CFX_RetainPtr<CFX_DIBitmap> pBitmap = buffer.GetBitmap();
@@ -2190,7 +2191,7 @@
 
   CFX_Matrix matrix = pShadingObj->m_Matrix;
   matrix.Concat(*pObj2Device);
-  DrawShading(pShadingObj->m_pShading, &matrix, rect,
+  DrawShading(pShadingObj->m_pShading.Get(), &matrix, rect,
               FXSYS_round(255 * pShadingObj->m_GeneralState.GetFillAlpha()),
               m_Options.m_ColorMode == RENDER_COLOR_ALPHA);
 }
@@ -2276,7 +2277,7 @@
                          original.y - mtPattern2Device.f);
         CFX_RenderDevice::StateRestorer restorer2(m_pDevice);
         CPDF_RenderStatus status;
-        status.Initialize(m_pContext, m_pDevice, nullptr, nullptr, this,
+        status.Initialize(m_pContext.Get(), m_pDevice, nullptr, nullptr, this,
                           pStates.get(), &m_Options,
                           pPattern->form()->m_Transparency, m_bDropObjects,
                           pFormResource);
@@ -2628,7 +2629,7 @@
   CPDF_RenderOptions options;
   options.m_ColorMode = bLuminosity ? RENDER_COLOR_NORMAL : RENDER_COLOR_ALPHA;
   CPDF_RenderStatus status;
-  status.Initialize(m_pContext, &bitmap_device, nullptr, nullptr, nullptr,
+  status.Initialize(m_pContext.Get(), &bitmap_device, nullptr, nullptr, nullptr,
                     nullptr, &options, 0, m_bDropObjects, pFormResource, true,
                     nullptr, 0, color_space_family, bLuminosity);
   status.RenderObjectList(&form, &matrix);
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index ab5ddd9..47fbac8 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -13,6 +13,7 @@
 #include "core/fpdfapi/page/cpdf_clippath.h"
 #include "core/fpdfapi/page/cpdf_graphicstates.h"
 #include "core/fpdfapi/render/cpdf_renderoptions.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxge/cfx_renderdevice.h"
 
 class CFX_PathData;
@@ -61,15 +62,15 @@
   bool ContinueSingleObject(CPDF_PageObject* pObj,
                             const CFX_Matrix* pObj2Device,
                             IFX_Pause* pPause);
-  CPDF_RenderContext* GetContext() { return m_pContext; }
+  CPDF_RenderContext* GetContext() const { return m_pContext.Get(); }
 
 #if defined _SKIA_SUPPORT_
   void DebugVerifyDeviceIsPreMultiplied() const;
 #endif
 
   CPDF_RenderOptions m_Options;
-  CPDF_Dictionary* m_pFormResource;
-  CPDF_Dictionary* m_pPageResource;
+  CFX_UnownedPtr<CPDF_Dictionary> m_pFormResource;
+  CFX_UnownedPtr<CPDF_Dictionary> m_pPageResource;
   std::vector<CPDF_Type3Font*> m_Type3FontCache;
 
  private:
@@ -157,7 +158,7 @@
   static const int kRenderMaxRecursionDepth = 64;
   static int s_CurrentRecursionDepth;
 
-  CPDF_RenderContext* m_pContext;
+  CFX_UnownedPtr<CPDF_RenderContext> m_pContext;
   bool m_bStopped;
   CFX_RenderDevice* m_pDevice;
   CFX_Matrix m_DeviceMatrix;
@@ -172,7 +173,7 @@
   bool m_bStdCS;
   uint32_t m_GroupFamily;
   bool m_bLoadMask;
-  CPDF_Type3Char* m_pType3Char;
+  CFX_UnownedPtr<CPDF_Type3Char> m_pType3Char;
   FX_ARGB m_T3FillColor;
   int m_curBlend;
 };
diff --git a/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp b/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp
index 74d506c..17e33af 100644
--- a/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp
+++ b/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp
@@ -67,8 +67,8 @@
     }
     m_Matrix.Scale(0.5f, 0.5f);
   }
-  m_pContext->GetBackground(m_pBitmapDevice->GetBitmap(), m_pObject, pOptions,
-                            &m_Matrix);
+  m_pContext->GetBackground(m_pBitmapDevice->GetBitmap(), m_pObject.Get(),
+                            pOptions, &m_Matrix);
   return true;
 }
 
diff --git a/core/fpdfapi/render/cpdf_scaledrenderbuffer.h b/core/fpdfapi/render/cpdf_scaledrenderbuffer.h
index 92fabef..47ab5ad 100644
--- a/core/fpdfapi/render/cpdf_scaledrenderbuffer.h
+++ b/core/fpdfapi/render/cpdf_scaledrenderbuffer.h
@@ -9,6 +9,7 @@
 
 #include <memory>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxge/cfx_defaultrenderdevice.h"
 
@@ -28,17 +29,18 @@
                   const CPDF_PageObject* pObj,
                   const CPDF_RenderOptions* pOptions,
                   int max_dpi);
-  CFX_RenderDevice* GetDevice() {
-    return m_pBitmapDevice ? m_pBitmapDevice.get() : m_pDevice;
+
+  CFX_RenderDevice* GetDevice() const {
+    return m_pBitmapDevice ? m_pBitmapDevice.get() : m_pDevice.Get();
   }
   CFX_Matrix* GetMatrix() { return &m_Matrix; }
   void OutputToDevice();
 
  private:
-  CFX_RenderDevice* m_pDevice;
-  CPDF_RenderContext* m_pContext;
+  CFX_UnownedPtr<CFX_RenderDevice> m_pDevice;
+  CFX_UnownedPtr<CPDF_RenderContext> m_pContext;
   FX_RECT m_Rect;
-  const CPDF_PageObject* m_pObject;
+  CFX_UnownedPtr<const CPDF_PageObject> m_pObject;
   std::unique_ptr<CFX_DefaultRenderDevice> m_pBitmapDevice;
   CFX_Matrix m_Matrix;
 };
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 97ea052..cd47f26 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -899,7 +899,7 @@
 }
 
 void CPDF_FormField::LoadDA() {
-  CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict;
+  CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict.Get();
   if (!pFormDict)
     return;
 
diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h
index f2038e4..f5c4c69 100644
--- a/core/fpdfdoc/cpdf_formfield.h
+++ b/core/fpdfdoc/cpdf_formfield.h
@@ -134,7 +134,7 @@
 #endif  // PDF_ENABLE_XFA
 
   float GetFontSize() const { return m_FontSize; }
-  CPDF_Font* GetFont() const { return m_pFont; }
+  CPDF_Font* GetFont() const { return m_pFont.Get(); }
 
   const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
   const CPDF_InterForm* GetForm() const { return m_pForm.Get(); }
@@ -176,7 +176,7 @@
   // Owned by InterForm parent.
   std::vector<CFX_UnownedPtr<CPDF_FormControl>> m_ControlList;
   float m_FontSize;
-  CPDF_Font* m_pFont;
+  CFX_UnownedPtr<CPDF_Font> m_pFont;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_FORMFIELD_H_
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index de99a5d..9c3730a 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -961,7 +961,7 @@
 }
 
 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) const {
-  return GetFont(m_pFormDict, m_pDocument.Get(), csNameTag);
+  return GetFont(m_pFormDict.Get(), m_pDocument.Get(), csNameTag);
 }
 
 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() const {
diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h
index 0a9b3e0..9dc0532 100644
--- a/core/fpdfdoc/cpdf_interform.h
+++ b/core/fpdfdoc/cpdf_interform.h
@@ -13,6 +13,7 @@
 
 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
 #include "core/fpdfdoc/cpdf_defaultappearance.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
 
@@ -109,12 +110,12 @@
   static bool s_bUpdateAP;
 
   CFX_UnownedPtr<CPDF_Document> const m_pDocument;
-  CPDF_Dictionary* m_pFormDict;
+  CFX_UnownedPtr<CPDF_Dictionary> m_pFormDict;
   std::map<const CPDF_Dictionary*, std::unique_ptr<CPDF_FormControl>>
       m_ControlMap;
   std::unique_ptr<CFieldTree> m_pFieldTree;
   CFX_ByteString m_bsEncoding;
-  IPDF_FormNotify* m_pFormNotify;
+  CFX_UnownedPtr<IPDF_FormNotify> m_pFormNotify;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_INTERFORM_H_
diff --git a/core/fpdfdoc/cpdf_link.cpp b/core/fpdfdoc/cpdf_link.cpp
index 20ec486..b622094 100644
--- a/core/fpdfdoc/cpdf_link.cpp
+++ b/core/fpdfdoc/cpdf_link.cpp
@@ -9,6 +9,14 @@
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfdoc/cpdf_nametree.h"
 
+CPDF_Link::CPDF_Link() {}
+
+CPDF_Link::CPDF_Link(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
+
+CPDF_Link::CPDF_Link(const CPDF_Link& that) = default;
+
+CPDF_Link::~CPDF_Link() {}
+
 CFX_FloatRect CPDF_Link::GetRect() {
   return m_pDict->GetRectFor("Rect");
 }
diff --git a/core/fpdfdoc/cpdf_link.h b/core/fpdfdoc/cpdf_link.h
index 162630d..82f50fe 100644
--- a/core/fpdfdoc/cpdf_link.h
+++ b/core/fpdfdoc/cpdf_link.h
@@ -9,23 +9,25 @@
 
 #include "core/fpdfdoc/cpdf_action.h"
 #include "core/fpdfdoc/cpdf_dest.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 
 class CPDF_Dictionary;
 
 class CPDF_Link {
  public:
-  CPDF_Link() : m_pDict(nullptr) {}
-  explicit CPDF_Link(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
+  CPDF_Link();
+  explicit CPDF_Link(CPDF_Dictionary* pDict);
+  CPDF_Link(const CPDF_Link& that);
+  ~CPDF_Link();
 
-  CPDF_Dictionary* GetDict() const { return m_pDict; }
-
+  CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
   CFX_FloatRect GetRect();
   CPDF_Dest GetDest(CPDF_Document* pDoc);
   CPDF_Action GetAction();
 
  private:
-  CPDF_Dictionary* m_pDict;
+  CFX_UnownedPtr<CPDF_Dictionary> m_pDict;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_LINK_H_
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 7a493c0..e3db1c6 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -108,6 +108,12 @@
 
 }  // namespace
 
+PDFTEXT_Obj::PDFTEXT_Obj() {}
+
+PDFTEXT_Obj::PDFTEXT_Obj(const PDFTEXT_Obj& that) = default;
+
+PDFTEXT_Obj::~PDFTEXT_Obj() {}
+
 FPDF_CHAR_INFO::FPDF_CHAR_INFO()
     : m_Unicode(0),
       m_Charcode(0),
@@ -799,7 +805,7 @@
 }
 
 FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
-  CPDF_TextObject* pTextObj = Obj.m_pTextObj;
+  CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get();
   if (!pTextObj->m_ContentMark.HasRef())
     return FPDFText_MarkedContent::Pass;
 
@@ -862,7 +868,7 @@
 }
 
 void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) {
-  CPDF_TextObject* pTextObj = Obj.m_pTextObj;
+  CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get();
   if (!pTextObj->m_ContentMark.HasRef())
     return;
 
@@ -952,7 +958,7 @@
 }
 
 void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
-  CPDF_TextObject* pTextObj = Obj.m_pTextObj;
+  CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get();
   if (fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f)
     return;
   CFX_Matrix formMatrix = Obj.m_formMatrix;
diff --git a/core/fpdftext/cpdf_textpage.h b/core/fpdftext/cpdf_textpage.h
index a183106..0f507de 100644
--- a/core/fpdftext/cpdf_textpage.h
+++ b/core/fpdftext/cpdf_textpage.h
@@ -84,7 +84,11 @@
 };
 
 struct PDFTEXT_Obj {
-  CPDF_TextObject* m_pTextObj;
+  PDFTEXT_Obj();
+  PDFTEXT_Obj(const PDFTEXT_Obj& that);
+  ~PDFTEXT_Obj();
+
+  CFX_UnownedPtr<CPDF_TextObject> m_pTextObj;
   CFX_Matrix m_formMatrix;
 };
 
diff --git a/core/fxcodec/codec/ccodec_jbig2module.h b/core/fxcodec/codec/ccodec_jbig2module.h
index 43abe04..e8dec94 100644
--- a/core/fxcodec/codec/ccodec_jbig2module.h
+++ b/core/fxcodec/codec/ccodec_jbig2module.h
@@ -10,6 +10,7 @@
 #include <memory>
 
 #include "core/fxcodec/fx_codec_def.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 
 class CJBig2_Context;
@@ -29,7 +30,7 @@
   CFX_RetainPtr<CPDF_StreamAcc> m_pSrcStream;
   uint8_t* m_dest_buf;
   uint32_t m_dest_pitch;
-  IFX_Pause* m_pPause;
+  CFX_UnownedPtr<IFX_Pause> m_pPause;
   std::unique_ptr<CJBig2_Context> m_pContext;
 };
 
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.h b/core/fxcodec/codec/ccodec_progressivedecoder.h
index 2b343b7..6dd7357 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.h
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.h
@@ -17,6 +17,7 @@
 #include "core/fxcodec/fx_codec_def.h"
 #include "core/fxcodec/lgif/cgifcontext.h"
 #include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxge/fx_dib.h"
 
@@ -127,12 +128,12 @@
   };
 
   CFX_RetainPtr<IFX_SeekableReadStream> m_pFile;
-  CCodec_ModuleMgr* m_pCodecMgr;
+  CFX_UnownedPtr<CCodec_ModuleMgr> m_pCodecMgr;
   FXJPEG_Context* m_pJpegContext;
   FXPNG_Context* m_pPngContext;
   std::unique_ptr<CGifContext> m_pGifContext;
   FXBMP_Context* m_pBmpContext;
-  CCodec_TiffContext* m_pTiffContext;
+  CFX_UnownedPtr<CCodec_TiffContext> m_pTiffContext;
   FXCODEC_IMAGE_TYPE m_imagType;
   uint32_t m_offSet;
   uint8_t* m_pSrcBuf;
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index 9e470f3..209a973 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -302,7 +302,7 @@
   if (m_pPngContext)
     m_pCodecMgr->GetPngModule()->Finish(m_pPngContext);
   if (m_pTiffContext)
-    m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext);
+    m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext.Get());
   FX_Free(m_pSrcBuf);
   FX_Free(m_pDecodeBuf);
   FX_Free(m_pSrcPalette);
@@ -1213,13 +1213,13 @@
         return false;
       }
       int32_t dummy_bpc;
-      bool ret = pTiffModule->LoadFrameInfo(m_pTiffContext, 0, &m_SrcWidth,
-                                            &m_SrcHeight, &m_SrcComponents,
-                                            &dummy_bpc, pAttribute);
+      bool ret = pTiffModule->LoadFrameInfo(
+          m_pTiffContext.Get(), 0, &m_SrcWidth, &m_SrcHeight, &m_SrcComponents,
+          &dummy_bpc, pAttribute);
       m_SrcComponents = 4;
       m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
       if (!ret) {
-        pTiffModule->DestroyDecoder(m_pTiffContext);
+        pTiffModule->DestroyDecoder(m_pTiffContext.Get());
         m_pTiffContext = nullptr;
         m_status = FXCODEC_STATUS_ERR_FORMAT;
         return false;
@@ -2170,7 +2170,7 @@
           m_SrcHeight == m_sizeY && m_startX == 0 && m_startY == 0 &&
           m_clipBox.left == 0 && m_clipBox.top == 0 &&
           m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) {
-        ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap);
+        ret = pTiffModule->Decode(m_pTiffContext.Get(), m_pDeviceBitmap);
         m_pDeviceBitmap = nullptr;
         m_pFile = nullptr;
         if (!ret) {
@@ -2189,7 +2189,7 @@
         m_status = FXCODEC_STATUS_ERR_MEMORY;
         return m_status;
       }
-      ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap);
+      ret = pTiffModule->Decode(m_pTiffContext.Get(), pDIBitmap);
       if (!ret) {
         m_pDeviceBitmap = nullptr;
         m_pFile = nullptr;
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
index 0d9f991..a8140bd 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
@@ -25,6 +25,8 @@
   m_ReplaceRect.right = 0;
 }
 
+CJBig2_GRDProc::~CJBig2_GRDProc() {}
+
 bool CJBig2_GRDProc::UseTemplate0Opt3() const {
   return (GBAT[0] == 3) && (GBAT[1] == -1) && (GBAT[2] == -3) &&
          (GBAT[3] == -1) && (GBAT[4] == 2) && (GBAT[5] == -2) &&
@@ -663,35 +665,35 @@
   CJBig2_Image* pImage = *m_pImage;
   if (GBTEMPLATE == 0) {
     if (UseTemplate0Opt3()) {
-      m_ProssiveStatus = decode_Arith_Template0_opt3(pImage, m_pArithDecoder,
-                                                     m_gbContext, pPause);
+      m_ProssiveStatus = decode_Arith_Template0_opt3(
+          pImage, m_pArithDecoder.Get(), m_gbContext, pPause);
     } else {
-      m_ProssiveStatus = decode_Arith_Template0_unopt(pImage, m_pArithDecoder,
-                                                      m_gbContext, pPause);
+      m_ProssiveStatus = decode_Arith_Template0_unopt(
+          pImage, m_pArithDecoder.Get(), m_gbContext, pPause);
     }
   } else if (GBTEMPLATE == 1) {
     if (UseTemplate1Opt3()) {
-      m_ProssiveStatus = decode_Arith_Template1_opt3(pImage, m_pArithDecoder,
-                                                     m_gbContext, pPause);
+      m_ProssiveStatus = decode_Arith_Template1_opt3(
+          pImage, m_pArithDecoder.Get(), m_gbContext, pPause);
     } else {
-      m_ProssiveStatus = decode_Arith_Template1_unopt(pImage, m_pArithDecoder,
-                                                      m_gbContext, pPause);
+      m_ProssiveStatus = decode_Arith_Template1_unopt(
+          pImage, m_pArithDecoder.Get(), m_gbContext, pPause);
     }
   } else if (GBTEMPLATE == 2) {
     if (UseTemplate23Opt3()) {
-      m_ProssiveStatus = decode_Arith_Template2_opt3(pImage, m_pArithDecoder,
-                                                     m_gbContext, pPause);
+      m_ProssiveStatus = decode_Arith_Template2_opt3(
+          pImage, m_pArithDecoder.Get(), m_gbContext, pPause);
     } else {
-      m_ProssiveStatus = decode_Arith_Template2_unopt(pImage, m_pArithDecoder,
-                                                      m_gbContext, pPause);
+      m_ProssiveStatus = decode_Arith_Template2_unopt(
+          pImage, m_pArithDecoder.Get(), m_gbContext, pPause);
     }
   } else {
     if (UseTemplate23Opt3()) {
-      m_ProssiveStatus = decode_Arith_Template3_opt3(pImage, m_pArithDecoder,
-                                                     m_gbContext, pPause);
+      m_ProssiveStatus = decode_Arith_Template3_opt3(
+          pImage, m_pArithDecoder.Get(), m_gbContext, pPause);
     } else {
-      m_ProssiveStatus = decode_Arith_Template3_unopt(pImage, m_pArithDecoder,
-                                                      m_gbContext, pPause);
+      m_ProssiveStatus = decode_Arith_Template3_unopt(
+          pImage, m_pArithDecoder.Get(), m_gbContext, pPause);
     }
   }
   m_ReplaceRect.left = 0;
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.h b/core/fxcodec/jbig2/JBig2_GrdProc.h
index 447447f..c6e8ae3 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.h
@@ -8,6 +8,7 @@
 #define CORE_FXCODEC_JBIG2_JBIG2_GRDPROC_H_
 
 #include "core/fxcodec/fx_codec_def.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_system.h"
 
@@ -20,6 +21,7 @@
 class CJBig2_GRDProc {
  public:
   CJBig2_GRDProc();
+  ~CJBig2_GRDProc();
 
   CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
                              JBig2ArithCtx* gbContext);
@@ -112,7 +114,7 @@
   uint8_t* m_pLine;
   FXCODEC_STATUS m_ProssiveStatus;
   CJBig2_Image** m_pImage;
-  CJBig2_ArithDecoder* m_pArithDecoder;
+  CFX_UnownedPtr<CJBig2_ArithDecoder> m_pArithDecoder;
   JBig2ArithCtx* m_gbContext;
   uint16_t m_DecodeType;
   int m_LTP;
diff --git a/core/fxcodec/lgif/cgifcontext.h b/core/fxcodec/lgif/cgifcontext.h
index 08a66c1..20d640e 100644
--- a/core/fxcodec/lgif/cgifcontext.h
+++ b/core/fxcodec/lgif/cgifcontext.h
@@ -11,6 +11,7 @@
 #include <vector>
 
 #include "core/fxcodec/lgif/fx_gif.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 
 class CCodec_GifModule;
@@ -44,7 +45,7 @@
   int32_t decode_status;
   uint32_t skip_size;
 
-  CCodec_GifModule* m_Module;
+  CFX_UnownedPtr<CCodec_GifModule> m_Module;
   char* err_ptr;
   CFX_ByteString cmt_data;
   std::unique_ptr<GifGCE> m_GifGCE;
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 6174f6e..22d8007 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -438,7 +438,7 @@
   CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
   CFX_RetainPtr<CFX_DIBitmap> m_pClipMask;
   CFX_RetainPtr<CFX_DIBitmap> m_pDevice;
-  const CFX_ClipRgn* m_pClipRgn;
+  CFX_UnownedPtr<const CFX_ClipRgn> m_pClipRgn;
 };
 
 void CFX_Renderer::CompositeSpan(uint8_t* dest_scan,
diff --git a/core/fxge/android/cfpf_skiafont.h b/core/fxge/android/cfpf_skiafont.h
index 657ced8..5686e9e 100644
--- a/core/fxge/android/cfpf_skiafont.h
+++ b/core/fxge/android/cfpf_skiafont.h
@@ -7,6 +7,7 @@
 #ifndef CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_
 #define CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxge/fx_font.h"
 
@@ -42,8 +43,8 @@
                 uint8_t uCharset);
 
  private:
-  CFPF_SkiaFontMgr* m_pFontMgr;
-  CFPF_SkiaFontDescriptor* m_pFontDes;
+  CFX_UnownedPtr<CFPF_SkiaFontMgr> m_pFontMgr;
+  CFX_UnownedPtr<CFPF_SkiaFontDescriptor> m_pFontDes;
   FXFT_Face m_Face;
   uint32_t m_dwStyle;
   uint8_t m_uCharset;
diff --git a/core/fxge/android/cfx_androidfontinfo.h b/core/fxge/android/cfx_androidfontinfo.h
index ce08f25..17bbf89 100644
--- a/core/fxge/android/cfx_androidfontinfo.h
+++ b/core/fxge/android/cfx_androidfontinfo.h
@@ -7,6 +7,7 @@
 #ifndef CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_
 #define CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxge/cfx_fontmapper.h"
 #include "core/fxge/fx_font.h"
@@ -39,7 +40,7 @@
   void DeleteFont(void* hFont) override;
 
  protected:
-  CFPF_SkiaFontMgr* m_pFontMgr;
+  CFX_UnownedPtr<CFPF_SkiaFontMgr> m_pFontMgr;
 };
 
 #endif  // CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_
diff --git a/core/fxge/cfx_facecache.h b/core/fxge/cfx_facecache.h
index 5857a63..d6847de 100644
--- a/core/fxge/cfx_facecache.h
+++ b/core/fxge/cfx_facecache.h
@@ -10,6 +10,7 @@
 #include <map>
 #include <memory>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxge/fx_font.h"
 #include "core/fxge/fx_freetype.h"
 
@@ -59,7 +60,7 @@
   std::map<CFX_ByteString, std::unique_ptr<CFX_SizeGlyphCache>> m_SizeMap;
   std::map<uint32_t, std::unique_ptr<CFX_PathData>> m_PathMap;
 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_
-  CFX_TypeFace* m_pTypeface;
+  CFX_UnownedPtr<CFX_TypeFace> m_pTypeface;
 #endif
 };
 
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index 4d8b407..f33da57 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -9,6 +9,7 @@
 
 #include <memory>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxge/fx_dib.h"
 #include "core/fxge/fx_font.h"
 
@@ -84,13 +85,11 @@
  public:
   class StateRestorer {
    public:
-    explicit StateRestorer(CFX_RenderDevice* pDevice) : m_pDevice(pDevice) {
-      m_pDevice->SaveState();
-    }
-    ~StateRestorer() { m_pDevice->RestoreState(false); }
+    explicit StateRestorer(CFX_RenderDevice* pDevice);
+    ~StateRestorer();
 
    private:
-    CFX_RenderDevice* m_pDevice;
+    CFX_UnownedPtr<CFX_RenderDevice> m_pDevice;
   };
 
   CFX_RenderDevice();
diff --git a/core/fxge/dib/cfx_bitmapcomposer.h b/core/fxge/dib/cfx_bitmapcomposer.h
index 6e961cb..cc4ecb1 100644
--- a/core/fxge/dib/cfx_bitmapcomposer.h
+++ b/core/fxge/dib/cfx_bitmapcomposer.h
@@ -10,6 +10,7 @@
 #include <vector>
 
 #include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxge/dib/cfx_scanlinecompositor.h"
 #include "core/fxge/dib/ifx_scanlinecomposer.h"
@@ -56,7 +57,7 @@
                         const uint8_t* scan_extra_alpha);
 
   CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
-  const CFX_ClipRgn* m_pClipRgn;
+  CFX_UnownedPtr<const CFX_ClipRgn> m_pClipRgn;
   FXDIB_Format m_SrcFormat;
   int m_DestLeft;
   int m_DestTop;
diff --git a/core/fxge/dib/cfx_imagerenderer.cpp b/core/fxge/dib/cfx_imagerenderer.cpp
index cff95fd..ec611ca 100644
--- a/core/fxge/dib/cfx_imagerenderer.cpp
+++ b/core/fxge/dib/cfx_imagerenderer.cpp
@@ -122,14 +122,14 @@
     m_pDevice->CompositeMask(
         m_pTransformer->result().left, m_pTransformer->result().top,
         pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0,
-        m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag);
+        m_BlendType, m_pClipRgn.Get(), m_bRgbByteOrder, m_AlphaFlag);
   } else {
     if (m_BitmapAlpha != 255)
       pBitmap->MultiplyAlpha(m_BitmapAlpha);
     m_pDevice->CompositeBitmap(
         m_pTransformer->result().left, m_pTransformer->result().top,
         pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType,
-        m_pClipRgn, m_bRgbByteOrder);
+        m_pClipRgn.Get(), m_bRgbByteOrder);
   }
   return false;
 }
diff --git a/core/fxge/dib/cfx_imagerenderer.h b/core/fxge/dib/cfx_imagerenderer.h
index f3d1286..cad621e 100644
--- a/core/fxge/dib/cfx_imagerenderer.h
+++ b/core/fxge/dib/cfx_imagerenderer.h
@@ -10,6 +10,7 @@
 #include <memory>
 
 #include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxge/dib/cfx_bitmapcomposer.h"
 #include "core/fxge/dib/cfx_dibitmap.h"
@@ -38,7 +39,7 @@
 
  private:
   CFX_RetainPtr<CFX_DIBitmap> m_pDevice;
-  const CFX_ClipRgn* m_pClipRgn;
+  CFX_UnownedPtr<const CFX_ClipRgn> m_pClipRgn;
   int m_BitmapAlpha;
   uint32_t m_MaskColor;
   CFX_Matrix m_Matrix;
diff --git a/core/fxge/dib/cstretchengine.h b/core/fxge/dib/cstretchengine.h
index 280641c..0490593 100644
--- a/core/fxge/dib/cstretchengine.h
+++ b/core/fxge/dib/cstretchengine.h
@@ -9,6 +9,7 @@
 
 #include <vector>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxge/fx_dib.h"
 
@@ -58,7 +59,7 @@
   int m_DestBpp;
   int m_SrcBpp;
   int m_bHasAlpha;
-  IFX_ScanlineComposer* m_pDestBitmap;
+  CFX_UnownedPtr<IFX_ScanlineComposer> m_pDestBitmap;
   int m_DestWidth;
   int m_DestHeight;
   FX_RECT m_DestClip;
diff --git a/core/fxge/ge/cfx_facecache.cpp b/core/fxge/ge/cfx_facecache.cpp
index 9c79444..6049729 100644
--- a/core/fxge/ge/cfx_facecache.cpp
+++ b/core/fxge/ge/cfx_facecache.cpp
@@ -90,7 +90,7 @@
 
 CFX_FaceCache::~CFX_FaceCache() {
 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_
-  SkSafeUnref(m_pTypeface);
+  SkSafeUnref(m_pTypeface.Get());
 #endif
 }
 
@@ -370,7 +370,7 @@
         new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()));
   }
 #endif
-  return m_pTypeface;
+  return m_pTypeface.Get();
 }
 #endif
 
diff --git a/core/fxge/ge/cfx_folderfontinfo.h b/core/fxge/ge/cfx_folderfontinfo.h
index 6aadb15..ad363b5 100644
--- a/core/fxge/ge/cfx_folderfontinfo.h
+++ b/core/fxge/ge/cfx_folderfontinfo.h
@@ -11,6 +11,7 @@
 #include <memory>
 #include <vector>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxge/cfx_fontmapper.h"
 #include "core/fxge/fx_font.h"
 #include "core/fxge/ifx_systemfontinfo.h"
@@ -62,7 +63,7 @@
 
   std::map<CFX_ByteString, std::unique_ptr<CFX_FontFaceInfo>> m_FontList;
   std::vector<CFX_ByteString> m_PathList;
-  CFX_FontMapper* m_pMapper;
+  CFX_UnownedPtr<CFX_FontMapper> m_pMapper;
 };
 
 #endif  // CORE_FXGE_GE_CFX_FOLDERFONTINFO_H_
diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp
index 229ede7..144675c 100644
--- a/core/fxge/ge/cfx_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -28,12 +28,12 @@
 
 namespace {
 
-typedef struct {
+struct OUTLINE_PARAMS {
   CFX_PathData* m_pPath;
   int m_CurX;
   int m_CurY;
   float m_CoordUnit;
-} OUTLINE_PARAMS;
+};
 
 #ifdef PDF_ENABLE_XFA
 
diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp
index f9153d1..4404833 100644
--- a/core/fxge/ge/cfx_renderdevice.cpp
+++ b/core/fxge/ge/cfx_renderdevice.cpp
@@ -1120,3 +1120,12 @@
   }
   return true;
 }
+
+CFX_RenderDevice::StateRestorer::StateRestorer(CFX_RenderDevice* pDevice)
+    : m_pDevice(pDevice) {
+  m_pDevice->SaveState();
+}
+
+CFX_RenderDevice::StateRestorer::~StateRestorer() {
+  m_pDevice->RestoreState(false);
+}
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 7d91ab2..f4b72fe 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -822,7 +822,7 @@
     skPaint.setAntiAlias(true);
     skPaint.setColor(m_fillColor);
     if (m_pTypeFace) {  // exclude placeholder test fonts
-      sk_sp<SkTypeface> typeface(SkSafeRef(m_pTypeFace));
+      sk_sp<SkTypeface> typeface(SkSafeRef(m_pTypeFace.Get()));
       skPaint.setTypeface(typeface);
     }
     skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
@@ -1266,8 +1266,8 @@
   CFX_GraphStateData m_clipState;
   CFX_GraphStateData m_drawState;
   CFX_Matrix m_clipMatrix;
-  CFX_SkiaDeviceDriver* m_pDriver;
-  CFX_TypeFace* m_pTypeFace;
+  CFX_UnownedPtr<CFX_SkiaDeviceDriver> m_pDriver;
+  CFX_UnownedPtr<CFX_TypeFace> m_pTypeFace;
   float m_fontSize;
   uint32_t m_fillColor;
   uint32_t m_strokeColor;
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 400babd..b5260c1 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -76,7 +76,7 @@
 }  // namespace
 
 struct PSGlyph {
-  CFX_Font* m_pFont;
+  CFX_UnownedPtr<CFX_Font> m_pFont;
   uint32_t m_GlyphIndex;
   bool m_bGlyphAdjust;
   float m_AdjustMatrix[4];
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index b495251..f648118 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -363,7 +363,7 @@
   CFX_ByteString FindFont(const CFX_ByteString& name);
 
   HDC m_hDC;
-  CFX_FontMapper* m_pMapper;
+  CFX_UnownedPtr<CFX_FontMapper> m_pMapper;
   CFX_ByteString m_LastFamily;
   CFX_ByteString m_KaiTi, m_FangSong;
 };
diff --git a/fpdfsdk/cba_annotiterator.h b/fpdfsdk/cba_annotiterator.h
index 5cbe8e3..36eacd9 100644
--- a/fpdfsdk/cba_annotiterator.h
+++ b/fpdfsdk/cba_annotiterator.h
@@ -10,6 +10,7 @@
 #include <vector>
 
 #include "core/fpdfdoc/cpdf_annot.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
 
@@ -37,7 +38,7 @@
                            std::vector<size_t>* aSelect);
 
   TabOrder m_eTabOrder;
-  CPDFSDK_PageView* m_pPageView;
+  CFX_UnownedPtr<CPDFSDK_PageView> m_pPageView;
   CPDF_Annot::Subtype m_nAnnotSubtype;
   std::vector<CPDFSDK_Annot*> m_Annots;
 };
diff --git a/fpdfsdk/cpdfsdk_annot.h b/fpdfsdk/cpdfsdk_annot.h
index 1053c00..abcdc2e 100644
--- a/fpdfsdk/cpdfsdk_annot.h
+++ b/fpdfsdk/cpdfsdk_annot.h
@@ -11,6 +11,7 @@
 #include "core/fpdfdoc/cpdf_annot.h"
 #include "core/fpdfdoc/cpdf_defaultappearance.h"
 #include "core/fxcrt/cfx_observable.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 #include "fpdfsdk/cfx_systemhandler.h"
 #include "fpdfsdk/fsdk_common.h"
@@ -52,13 +53,13 @@
 #endif  // PDF_ENABLE_XFA
 
   void SetPage(CPDFSDK_PageView* pPageView);
-  CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
+  CPDFSDK_PageView* GetPageView() const { return m_pPageView.Get(); }
 
   bool IsSelected();
   void SetSelected(bool bSelected);
 
  protected:
-  CPDFSDK_PageView* m_pPageView;
+  CFX_UnownedPtr<CPDFSDK_PageView> m_pPageView;
   bool m_bSelected;
 };
 
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index a1cd8c7..7d9357a 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -88,9 +88,8 @@
           m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr);
       }
     }
-    return m_hMixXFAWidget;
+    return m_hMixXFAWidget.Get();
   }
-
   return nullptr;
 }
 
@@ -113,10 +112,11 @@
     return nullptr;
 
   if (!m_pWidgetHandler) {
-    if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
+    CXFA_FFDocView* pDocView = pContext->GetXFADocView();
+    if (pDocView)
       m_pWidgetHandler = pDocView->GetWidgetHandler();
   }
-  return m_pWidgetHandler;
+  return m_pWidgetHandler.Get();
 }
 
 static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h
index a5e5b70..fe8d015 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -12,6 +12,7 @@
 #include "core/fpdfdoc/cpdf_aaction.h"
 #include "core/fpdfdoc/cpdf_action.h"
 #include "core/fpdfdoc/cpdf_annot.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
 #include "fpdfsdk/cpdfsdk_baannot.h"
@@ -166,8 +167,8 @@
   int32_t m_nValueAge;
 
 #ifdef PDF_ENABLE_XFA
-  mutable CXFA_FFWidget* m_hMixXFAWidget;
-  mutable CXFA_FFWidgetHandler* m_pWidgetHandler;
+  mutable CFX_UnownedPtr<CXFA_FFWidget> m_hMixXFAWidget;
+  mutable CFX_UnownedPtr<CXFA_FFWidgetHandler> m_pWidgetHandler;
 #endif  // PDF_ENABLE_XFA
 };
 
diff --git a/fpdfsdk/cpdfsdk_widgethandler.h b/fpdfsdk/cpdfsdk_widgethandler.h
index a772471..4e8c9ef 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.h
+++ b/fpdfsdk/cpdfsdk_widgethandler.h
@@ -100,11 +100,13 @@
   void SetFormFiller(CFFL_InteractiveFormFiller* pFiller) {
     m_pFormFiller = pFiller;
   }
-  CFFL_InteractiveFormFiller* GetFormFiller() { return m_pFormFiller; }
+  CFFL_InteractiveFormFiller* GetFormFiller() const {
+    return m_pFormFiller.Get();
+  }
 
  private:
   CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
-  CFFL_InteractiveFormFiller* m_pFormFiller;
+  CFX_UnownedPtr<CFFL_InteractiveFormFiller> m_pFormFiller;
 };
 
 #endif  // FPDFSDK_CPDFSDK_WIDGETHANDLER_H_
diff --git a/fpdfsdk/cpdfsdk_xfawidget.cpp b/fpdfsdk/cpdfsdk_xfawidget.cpp
index 902ff2a..af08023 100644
--- a/fpdfsdk/cpdfsdk_xfawidget.cpp
+++ b/fpdfsdk/cpdfsdk_xfawidget.cpp
@@ -16,12 +16,14 @@
       m_pInterForm(pInterForm),
       m_hXFAWidget(pAnnot) {}
 
+CPDFSDK_XFAWidget::~CPDFSDK_XFAWidget() {}
+
 bool CPDFSDK_XFAWidget::IsXFAField() {
   return true;
 }
 
 CXFA_FFWidget* CPDFSDK_XFAWidget::GetXFAWidget() const {
-  return m_hXFAWidget;
+  return m_hXFAWidget.Get();
 }
 
 CPDF_Annot::Subtype CPDFSDK_XFAWidget::GetAnnotSubtype() const {
diff --git a/fpdfsdk/cpdfsdk_xfawidget.h b/fpdfsdk/cpdfsdk_xfawidget.h
index 9d0be75..42448b8 100644
--- a/fpdfsdk/cpdfsdk_xfawidget.h
+++ b/fpdfsdk/cpdfsdk_xfawidget.h
@@ -7,6 +7,7 @@
 #ifndef FPDFSDK_CPDFSDK_XFAWIDGET_H_
 #define FPDFSDK_CPDFSDK_XFAWIDGET_H_
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
 #include "fpdfsdk/cpdfsdk_annot.h"
@@ -20,18 +21,19 @@
   CPDFSDK_XFAWidget(CXFA_FFWidget* pAnnot,
                     CPDFSDK_PageView* pPageView,
                     CPDFSDK_InterForm* pInterForm);
-  ~CPDFSDK_XFAWidget() override {}
+  ~CPDFSDK_XFAWidget() override;
 
+  // CPDFSDK_Annot:
   bool IsXFAField() override;
   CXFA_FFWidget* GetXFAWidget() const override;
   CPDF_Annot::Subtype GetAnnotSubtype() const override;
   CFX_FloatRect GetRect() const override;
 
-  CPDFSDK_InterForm* GetInterForm() { return m_pInterForm; }
+  CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm.Get(); }
 
  private:
-  CPDFSDK_InterForm* m_pInterForm;
-  CXFA_FFWidget* m_hXFAWidget;
+  CFX_UnownedPtr<CPDFSDK_InterForm> m_pInterForm;
+  CFX_UnownedPtr<CXFA_FFWidget> m_hXFAWidget;
 };
 
 #endif  // FPDFSDK_CPDFSDK_XFAWIDGET_H_
diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp
index c233c13..323dcf4 100644
--- a/fpdfsdk/formfiller/cffl_checkbox.cpp
+++ b/fpdfsdk/formfiller/cffl_checkbox.cpp
@@ -48,7 +48,7 @@
 
       bool bReset = false;
       bool bExit = false;
-      CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget);
+      CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get());
       m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp(
           &pObserved, pPageView, bReset, bExit, nFlags);
       if (!pObserved) {
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index 1f2491f..7887593 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -38,8 +38,10 @@
   if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)
     cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT;
 
-  if (!m_pFontMap)
-    m_pFontMap = pdfium::MakeUnique<CBA_FontMap>(m_pWidget, GetSystemHandler());
+  if (!m_pFontMap) {
+    m_pFontMap =
+        pdfium::MakeUnique<CBA_FontMap>(m_pWidget.Get(), GetSystemHandler());
+  }
   cp.pFontMap = m_pFontMap.get();
   cp.pFocusHandler = this;
   return cp;
diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp
index 947c495..2bc240f 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_formfiller.cpp
@@ -356,16 +356,14 @@
     }
   } else {
     PWL_CREATEPARAM cp = GetCreateParam();
-    cp.pAttachedWidget.Reset(m_pWidget);
+    cp.pAttachedWidget.Reset(m_pWidget.Get());
 
     CFFL_PrivateData* pPrivateData = new CFFL_PrivateData;
-    pPrivateData->pWidget = m_pWidget;
+    pPrivateData->pWidget = m_pWidget.Get();
     pPrivateData->pPageView = pPageView;
     pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge();
     pPrivateData->nValueAge = 0;
-
     cp.pAttachedData = pPrivateData;
-
     pWnd = NewPDFWindow(cp, pPageView);
     m_Maps[pPageView] = pWnd;
   }
@@ -506,7 +504,7 @@
     bool bExit = false;
     CFFL_InteractiveFormFiller* pFormFiller =
         m_pFormFillEnv->GetInteractiveFormFiller();
-    CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget);
+    CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get());
     pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, bRC, bExit, nFlag);
     if (!pObserved || bExit)
       return true;
@@ -522,11 +520,11 @@
       return true;
     }
     SaveData(pPageView);
-    pFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag);
+    pFormFiller->OnCalculate(m_pWidget.Get(), pPageView, bExit, nFlag);
     if (bExit)
       return true;
 
-    pFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag);
+    pFormFiller->OnFormat(m_pWidget.Get(), pPageView, bExit, nFlag);
   }
   return true;
 }
@@ -582,7 +580,7 @@
                                    bool bDestroyPDFWindow) {
   m_bValid = false;
 
-  InvalidateRect(GetViewBBox(pPageView, m_pWidget));
+  InvalidateRect(GetViewBBox(pPageView, m_pWidget.Get()));
   if (bDestroyPDFWindow)
     DestroyPDFWindow(pPageView);
 }
diff --git a/fpdfsdk/formfiller/cffl_formfiller.h b/fpdfsdk/formfiller/cffl_formfiller.h
index f9a155b..bbb1e4b 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.h
+++ b/fpdfsdk/formfiller/cffl_formfiller.h
@@ -140,7 +140,7 @@
   void SetChangeMark();
 
   virtual void InvalidateRect(const FX_RECT& rect);
-  CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot; }
+  CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot.Get(); }
 
  protected:
   using CFFL_PageView2PDFWindow = std::map<CPDFSDK_PageView*, CPWL_Wnd*>;
@@ -154,8 +154,8 @@
   void DestroyWindows();
 
   CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
-  CPDFSDK_Widget* m_pWidget;
-  CPDFSDK_Annot* m_pAnnot;
+  CFX_UnownedPtr<CPDFSDK_Widget> m_pWidget;
+  CFX_UnownedPtr<CPDFSDK_Annot> m_pAnnot;
   bool m_bValid;
   CFFL_PageView2PDFWindow m_Maps;
   CFX_PointF m_ptOldPos;
diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp
index 556e0e1..399e390 100644
--- a/fpdfsdk/formfiller/cffl_listbox.cpp
+++ b/fpdfsdk/formfiller/cffl_listbox.cpp
@@ -25,12 +25,9 @@
 
 PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() {
   PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
-
   uint32_t dwFieldFlag = m_pWidget->GetFieldFlags();
-
-  if (dwFieldFlag & FIELDFLAG_MULTISELECT) {
+  if (dwFieldFlag & FIELDFLAG_MULTISELECT)
     cp.dwFlags |= PLBS_MULTIPLESEL;
-  }
 
   cp.dwFlags |= PWS_VSCROLL;
 
@@ -39,10 +36,9 @@
 
   if (!m_pFontMap) {
     m_pFontMap = pdfium::MakeUnique<CBA_FontMap>(
-        m_pWidget, m_pFormFillEnv->GetSysHandler());
+        m_pWidget.Get(), m_pFormFillEnv->GetSysHandler());
   }
   cp.pFontMap = m_pFontMap.get();
-
   return cp;
 }
 
diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp
index e78160e..68f5cb0 100644
--- a/fpdfsdk/formfiller/cffl_radiobutton.cpp
+++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp
@@ -51,7 +51,7 @@
 
       bool bReset = false;
       bool bExit = false;
-      CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget);
+      CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get());
       m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp(
           &pObserved, pPageView, bReset, bExit, nFlags);
       if (!pObserved || bReset || bExit)
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp
index 71fc929..b874a51 100644
--- a/fpdfsdk/formfiller/cffl_textfield.cpp
+++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -28,34 +28,25 @@
 
 PWL_CREATEPARAM CFFL_TextField::GetCreateParam() {
   PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
-
   int nFlags = m_pWidget->GetFieldFlags();
-
-  if (nFlags & FIELDFLAG_PASSWORD) {
+  if (nFlags & FIELDFLAG_PASSWORD)
     cp.dwFlags |= PES_PASSWORD;
-  }
 
   if (nFlags & FIELDFLAG_MULTILINE) {
     cp.dwFlags |= PES_MULTILINE | PES_AUTORETURN | PES_TOP;
-
-    if (!(nFlags & FIELDFLAG_DONOTSCROLL)) {
+    if (!(nFlags & FIELDFLAG_DONOTSCROLL))
       cp.dwFlags |= PWS_VSCROLL | PES_AUTOSCROLL;
-    }
   } else {
     cp.dwFlags |= PES_CENTER;
-
-    if (!(nFlags & FIELDFLAG_DONOTSCROLL)) {
+    if (!(nFlags & FIELDFLAG_DONOTSCROLL))
       cp.dwFlags |= PES_AUTOSCROLL;
-    }
   }
 
-  if (nFlags & FIELDFLAG_COMB) {
+  if (nFlags & FIELDFLAG_COMB)
     cp.dwFlags |= PES_CHARARRAY;
-  }
 
-  if (nFlags & FIELDFLAG_RICHTEXT) {
+  if (nFlags & FIELDFLAG_RICHTEXT)
     cp.dwFlags |= PES_RICH;
-  }
 
   cp.dwFlags |= PES_UNDO;
 
@@ -71,14 +62,12 @@
       cp.dwFlags |= PES_RIGHT;
       break;
   }
-
   if (!m_pFontMap) {
     m_pFontMap = pdfium::MakeUnique<CBA_FontMap>(
-        m_pWidget, m_pFormFillEnv->GetSysHandler());
+        m_pWidget.Get(), m_pFormFillEnv->GetSysHandler());
   }
   cp.pFontMap = m_pFontMap.get();
   cp.pFocusHandler = this;
-
   return cp;
 }
 
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index 1f73887..28af1ac 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -123,13 +123,12 @@
 }
 
 struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO {
-  IFX_SystemFontInfo* m_pFontInfo;
+  CFX_UnownedPtr<IFX_SystemFontInfo> m_pFontInfo;
 };
 
 static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) {
   auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
-  // TODO(thestig): Should this be set to nullptr too?
-  delete pDefault->m_pFontInfo;
+  delete pDefault->m_pFontInfo.Release();
 }
 
 static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) {
diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp
index 449121d..6409f70 100644
--- a/fpdfsdk/fpdfdoc_unittest.cpp
+++ b/fpdfsdk/fpdfdoc_unittest.cpp
@@ -87,7 +87,7 @@
 
  protected:
   std::unique_ptr<CPDF_TestPdfDocument> m_pDoc;
-  CPDF_IndirectObjectHolder* m_pIndirectObjs;
+  CFX_UnownedPtr<CPDF_IndirectObjectHolder> m_pIndirectObjs;
   std::unique_ptr<CPDF_Dictionary> m_pRootObj;
 };
 
@@ -116,25 +116,25 @@
     auto bookmarks = CreateDictObjs(3);
 
     bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
-    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(),
                                                 bookmarks[0].num);
-    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
+    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(),
                                                 bookmarks[2].num);
 
     bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
-    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(),
                                                 bookmarks[0].num);
-    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Prev", m_pIndirectObjs,
+    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Prev", m_pIndirectObjs.Get(),
                                                 bookmarks[1].num);
 
     bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
     bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
-    bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+    bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(),
                                                 bookmarks[1].num);
-    bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
+    bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(),
                                                 bookmarks[2].num);
 
-    m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
+    m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(),
                                           bookmarks[0].num);
 
     // Title with no match.
@@ -159,25 +159,25 @@
     auto bookmarks = CreateDictObjs(3);
 
     bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
-    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(),
                                                 bookmarks[0].num);
-    bookmarks[1].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+    bookmarks[1].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(),
                                                 bookmarks[2].num);
 
     bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
-    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(),
                                                 bookmarks[1].num);
-    bookmarks[2].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+    bookmarks[2].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(),
                                                 bookmarks[1].num);
 
     bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
     bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
-    bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+    bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(),
                                                 bookmarks[1].num);
-    bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
+    bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(),
                                                 bookmarks[2].num);
 
-    m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
+    m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(),
                                           bookmarks[0].num);
 
     // Title with no match.
@@ -194,31 +194,31 @@
     auto bookmarks = CreateDictObjs(4);
 
     bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
-    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(),
                                                 bookmarks[0].num);
-    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
+    bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(),
                                                 bookmarks[2].num);
 
     bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
-    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(),
                                                 bookmarks[0].num);
-    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
+    bookmarks[2].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(),
                                                 bookmarks[3].num);
 
     bookmarks[3].obj->SetNewFor<CPDF_String>("Title", L"Chapter 3");
-    bookmarks[3].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+    bookmarks[3].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(),
                                                 bookmarks[0].num);
-    bookmarks[3].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
+    bookmarks[3].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(),
                                                 bookmarks[1].num);
 
     bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
     bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
-    bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+    bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(),
                                                 bookmarks[1].num);
-    bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
+    bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(),
                                                 bookmarks[2].num);
 
-    m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
+    m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(),
                                           bookmarks[0].num);
 
     // Title with no match.
diff --git a/fpdfsdk/fxedit/fxet_edit.cpp b/fpdfsdk/fxedit/fxet_edit.cpp
index cf4fdc3..0e86562 100644
--- a/fpdfsdk/fxedit/fxet_edit.cpp
+++ b/fpdfsdk/fxedit/fxet_edit.cpp
@@ -145,7 +145,7 @@
 
 CFX_Edit_Provider::~CFX_Edit_Provider() {}
 
-IPVT_FontMap* CFX_Edit_Provider::GetFontMap() {
+IPVT_FontMap* CFX_Edit_Provider::GetFontMap() const {
   return m_pFontMap;
 }
 
diff --git a/fpdfsdk/fxedit/fxet_edit.h b/fpdfsdk/fxedit/fxet_edit.h
index ebc326f..01759aa 100644
--- a/fpdfsdk/fxedit/fxet_edit.h
+++ b/fpdfsdk/fxedit/fxet_edit.h
@@ -13,6 +13,7 @@
 
 #include "core/fpdfdoc/cpvt_secprops.h"
 #include "core/fpdfdoc/cpvt_wordprops.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "fpdfsdk/fxedit/fx_edit.h"
 
 class CFFL_FormFiller;
@@ -158,7 +159,7 @@
   void Undo() override;
 
  private:
-  CFX_Edit* m_pEdit;
+  CFX_UnownedPtr<CFX_Edit> m_pEdit;
 
   CPVT_WordPlace m_wpOld;
   CPVT_WordPlace m_wpNew;
@@ -181,7 +182,7 @@
   void Undo() override;
 
  private:
-  CFX_Edit* m_pEdit;
+  CFX_UnownedPtr<CFX_Edit> m_pEdit;
 
   CPVT_WordPlace m_wpOld;
   CPVT_WordPlace m_wpNew;
@@ -205,7 +206,7 @@
   void Undo() override;
 
  private:
-  CFX_Edit* m_pEdit;
+  CFX_UnownedPtr<CFX_Edit> m_pEdit;
 
   CPVT_WordPlace m_wpOld;
   CPVT_WordPlace m_wpNew;
@@ -232,7 +233,7 @@
   void Undo() override;
 
  private:
-  CFX_Edit* m_pEdit;
+  CFX_UnownedPtr<CFX_Edit> m_pEdit;
 
   CPVT_WordPlace m_wpOld;
   CPVT_WordPlace m_wpNew;
@@ -255,7 +256,7 @@
   void Undo() override;
 
  private:
-  CFX_Edit* m_pEdit;
+  CFX_UnownedPtr<CFX_Edit> m_pEdit;
 
   CPVT_WordRange m_wrSel;
   CFX_WideString m_swText;
@@ -275,7 +276,7 @@
   void Undo() override;
 
  private:
-  CFX_Edit* m_pEdit;
+  CFX_UnownedPtr<CFX_Edit> m_pEdit;
 
   CPVT_WordPlace m_wpOld;
   CPVT_WordPlace m_wpNew;
@@ -449,8 +450,8 @@
 
  private:
   std::unique_ptr<CPDF_VariableText> m_pVT;
-  CPWL_EditCtrl* m_pNotify;
-  CPWL_Edit* m_pOprNotify;
+  CFX_UnownedPtr<CPWL_EditCtrl> m_pNotify;
+  CFX_UnownedPtr<CPWL_Edit> m_pOprNotify;
   std::unique_ptr<CFX_Edit_Provider> m_pVTProvider;
   CPVT_WordPlace m_wpCaret;
   CPVT_WordPlace m_wpOldCaret;
@@ -485,7 +486,7 @@
   const CPVT_WordPlace& GetAt() const;
 
  private:
-  CFX_Edit* m_pEdit;
+  CFX_UnownedPtr<CFX_Edit> m_pEdit;
   CPDF_VariableText::Iterator* m_pVTIterator;
 };
 
@@ -494,7 +495,7 @@
   explicit CFX_Edit_Provider(IPVT_FontMap* pFontMap);
   ~CFX_Edit_Provider() override;
 
-  IPVT_FontMap* GetFontMap();
+  IPVT_FontMap* GetFontMap() const;
 
   // CPDF_VariableText::Provider:
   int32_t GetCharWidth(int32_t nFontIndex, uint16_t word) override;
diff --git a/fpdfsdk/fxedit/fxet_list.cpp b/fpdfsdk/fxedit/fxet_list.cpp
index c8fef94..a3badf3 100644
--- a/fpdfsdk/fxedit/fxet_list.cpp
+++ b/fpdfsdk/fxedit/fxet_list.cpp
@@ -590,7 +590,7 @@
 
 void CFX_ListCtrl::AddItem(const CFX_WideString& str) {
   auto pListItem = pdfium::MakeUnique<CFX_ListItem>();
-  pListItem->SetFontMap(m_pFontMap);
+  pListItem->SetFontMap(m_pFontMap.Get());
   pListItem->SetFontSize(m_fFontSize);
   pListItem->SetText(str);
   m_ListItems.push_back(std::move(pListItem));
diff --git a/fpdfsdk/fxedit/fxet_list.h b/fpdfsdk/fxedit/fxet_list.h
index cd6e2dd..b4b0a56 100644
--- a/fpdfsdk/fxedit/fxet_list.h
+++ b/fpdfsdk/fxedit/fxet_list.h
@@ -11,6 +11,7 @@
 #include <memory>
 #include <vector>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "fpdfsdk/fxedit/fx_edit.h"
 
@@ -263,7 +264,7 @@
   void SetItemSelect(int32_t nItemIndex, bool bSelected);
   int32_t GetLastSelected() const;
 
-  CPWL_List_Notify* m_pNotify;
+  CFX_UnownedPtr<CPWL_List_Notify> m_pNotify;
   bool m_bNotifyFlag;
   CFX_PointF m_ptScrollPos;
   CPLST_Select m_aSelItems;  // for multiple
@@ -273,7 +274,7 @@
   int32_t m_nCaretIndex;     // for multiple
   std::vector<std::unique_ptr<CFX_ListItem>> m_ListItems;
   float m_fFontSize;
-  IPVT_FontMap* m_pFontMap;
+  CFX_UnownedPtr<IPVT_FontMap> m_pFontMap;
   bool m_bMultiple;
 };
 
diff --git a/fpdfsdk/javascript/JS_EventHandler.h b/fpdfsdk/javascript/JS_EventHandler.h
index 5dcb70b..82d9d6a 100644
--- a/fpdfsdk/javascript/JS_EventHandler.h
+++ b/fpdfsdk/javascript/JS_EventHandler.h
@@ -172,7 +172,7 @@
 
   CFX_WideString m_strTargetName;
   CFX_WideString m_strSourceName;
-  CFX_WideString* m_pWideStrChange;
+  CFX_UnownedPtr<CFX_WideString> m_pWideStrChange;
   CFX_WideString m_WideStrChangeDu;
   CFX_WideString m_WideStrChangeEx;
   int m_nCommitKey;
@@ -184,12 +184,12 @@
   int* m_pISelStart;
   int m_nSelStartDu;
   bool m_bWillCommit;
-  CFX_WideString* m_pValue;
+  CFX_UnownedPtr<CFX_WideString> m_pValue;
   bool m_bFieldFull;
   bool* m_pbRc;
   bool m_bRcDu;
 
-  CPDF_Bookmark* m_pTargetBookMark;
+  CFX_UnownedPtr<CPDF_Bookmark> m_pTargetBookMark;
   CPDFSDK_FormFillEnvironment::ObservedPtr m_pTargetFormFillEnv;
   CPDFSDK_Annot::ObservedPtr m_pTargetAnnot;
 };
diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.h b/fpdfsdk/pdfwindow/PWL_ComboBox.h
index 0dfb3bd..27cdb61 100644
--- a/fpdfsdk/pdfwindow/PWL_ComboBox.h
+++ b/fpdfsdk/pdfwindow/PWL_ComboBox.h
@@ -52,7 +52,7 @@
   CPWL_ComboBox();
   ~CPWL_ComboBox() override;
 
-  CPWL_Edit* GetEdit() const { return m_pEdit; }
+  CPWL_Edit* GetEdit() const { return m_pEdit.Get(); }
 
   // CPWL_Wnd:
   CFX_ByteString GetClassName() const override;
@@ -93,14 +93,14 @@
   void CreateListBox(const PWL_CREATEPARAM& cp);
   void SetPopup(bool bPopup);
 
-  CPWL_CBEdit* m_pEdit;
-  CPWL_CBButton* m_pButton;
-  CPWL_CBListBox* m_pList;
+  CFX_UnownedPtr<CPWL_CBEdit> m_pEdit;
+  CFX_UnownedPtr<CPWL_CBButton> m_pButton;
+  CFX_UnownedPtr<CPWL_CBListBox> m_pList;
   bool m_bPopup;
   CFX_FloatRect m_rcOldWindow;
   int32_t m_nPopupWhere;
   int32_t m_nSelectItem;
-  IPWL_Filler_Notify* m_pFillerNotify;
+  CFX_UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify;
   CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
 };
 
diff --git a/fpdfsdk/pdfwindow/PWL_Edit.h b/fpdfsdk/pdfwindow/PWL_Edit.h
index bd37991..82c1f19 100644
--- a/fpdfsdk/pdfwindow/PWL_Edit.h
+++ b/fpdfsdk/pdfwindow/PWL_Edit.h
@@ -134,7 +134,7 @@
   CPVT_WordRange GetSameWordsRange(const CPVT_WordPlace& place,
                                    bool bLatin,
                                    bool bArabic) const;
-  IPWL_Filler_Notify* m_pFillerNotify;
+  CFX_UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify;
   bool m_bFocus;
   CFX_FloatRect m_rcOldWindow;
   CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
diff --git a/fpdfsdk/pdfwindow/PWL_Icon.cpp b/fpdfsdk/pdfwindow/PWL_Icon.cpp
index 3ae7244..e1397bf 100644
--- a/fpdfsdk/pdfwindow/PWL_Icon.cpp
+++ b/fpdfsdk/pdfwindow/PWL_Icon.cpp
@@ -55,8 +55,8 @@
   m_pPDFStream = pStream;
 }
 
-CPDF_Stream* CPWL_Image::GetPDFStream() {
-  return m_pPDFStream;
+CPDF_Stream* CPWL_Image::GetPDFStream() const {
+  return m_pPDFStream.Get();
 }
 
 void CPWL_Image::GetImageSize(float& fWidth, float& fHeight) {
@@ -114,8 +114,8 @@
 
 CPWL_Icon::~CPWL_Icon() {}
 
-CPDF_IconFit* CPWL_Icon::GetIconFit() {
-  return m_pIconFit;
+CPDF_IconFit* CPWL_Icon::GetIconFit() const {
+  return m_pIconFit.Get();
 }
 
 int32_t CPWL_Icon::GetScaleMethod() {
diff --git a/fpdfsdk/pdfwindow/PWL_Icon.h b/fpdfsdk/pdfwindow/PWL_Icon.h
index 49ac1f3..c5d116b 100644
--- a/fpdfsdk/pdfwindow/PWL_Icon.h
+++ b/fpdfsdk/pdfwindow/PWL_Icon.h
@@ -7,6 +7,7 @@
 #ifndef FPDFSDK_PDFWINDOW_PWL_ICON_H_
 #define FPDFSDK_PDFWINDOW_PWL_ICON_H_
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_string.h"
 #include "fpdfsdk/pdfwindow/PWL_Wnd.h"
 
@@ -19,7 +20,7 @@
 
   virtual void GetScale(float& fHScale, float& fVScale);
   virtual void GetImageOffset(float& x, float& y);
-  virtual CPDF_Stream* GetPDFStream();
+  virtual CPDF_Stream* GetPDFStream() const;
 
  public:
   void SetPDFStream(CPDF_Stream* pStream);
@@ -29,7 +30,7 @@
   void SetImageAlias(const char* sImageAlias);
 
  protected:
-  CPDF_Stream* m_pPDFStream;
+  CFX_UnownedPtr<CPDF_Stream> m_pPDFStream;
   CFX_ByteString m_sImageAlias;
 };
 
@@ -38,7 +39,7 @@
   CPWL_Icon();
   ~CPWL_Icon() override;
 
-  virtual CPDF_IconFit* GetIconFit();
+  virtual CPDF_IconFit* GetIconFit() const;
 
   // CPWL_Image
   void GetScale(float& fHScale, float& fVScale) override;
@@ -51,7 +52,7 @@
   void SetIconFit(CPDF_IconFit* pIconFit) { m_pIconFit = pIconFit; }
 
  private:
-  CPDF_IconFit* m_pIconFit;
+  CFX_UnownedPtr<CPDF_IconFit> m_pIconFit;
 };
 
 #endif  // FPDFSDK_PDFWINDOW_PWL_ICON_H_
diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.cpp b/fpdfsdk/pdfwindow/PWL_ListBox.cpp
index b682959..09487c3 100644
--- a/fpdfsdk/pdfwindow/PWL_ListBox.cpp
+++ b/fpdfsdk/pdfwindow/PWL_ListBox.cpp
@@ -36,7 +36,8 @@
   Info.fSmallStep = fSmallStep;
   Info.fBigStep = fBigStep;
 
-  m_pList->OnNotify(m_pList, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
+  m_pList->OnNotify(m_pList.Get(), PNM_SETSCROLLINFO, SBT_VSCROLL,
+                    reinterpret_cast<intptr_t>(&Info));
 
   if (CPWL_ScrollBar* pScroll = m_pList->GetVScrollBar()) {
     if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
@@ -55,7 +56,8 @@
 }
 
 void CPWL_List_Notify::IOnSetScrollPosY(float fy) {
-  m_pList->OnNotify(m_pList, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
+  m_pList->OnNotify(m_pList.Get(), PNM_SETSCROLLPOS, SBT_VSCROLL,
+                    reinterpret_cast<intptr_t>(&fy));
 }
 
 void CPWL_List_Notify::IOnInvalidateRect(CFX_FloatRect* pRect) {
diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.h b/fpdfsdk/pdfwindow/PWL_ListBox.h
index 0de9c91..75d23bb 100644
--- a/fpdfsdk/pdfwindow/PWL_ListBox.h
+++ b/fpdfsdk/pdfwindow/PWL_ListBox.h
@@ -41,7 +41,7 @@
                    const CPVT_WordPlace& place);
 
  private:
-  CPWL_ListBox* m_pList;
+  CFX_UnownedPtr<CPWL_ListBox> m_pList;
 };
 
 class CPWL_ListBox : public CPWL_Wnd {
@@ -109,7 +109,7 @@
   std::unique_ptr<CPWL_List_Notify> m_pListNotify;
   bool m_bMouseDown;
   bool m_bHoverSel;
-  IPWL_Filler_Notify* m_pFillerNotify;
+  CFX_UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify;
 
  private:
   CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
diff --git a/fpdfsdk/pdfwindow/PWL_ScrollBar.h b/fpdfsdk/pdfwindow/PWL_ScrollBar.h
index 50b0801..41df655 100644
--- a/fpdfsdk/pdfwindow/PWL_ScrollBar.h
+++ b/fpdfsdk/pdfwindow/PWL_ScrollBar.h
@@ -7,6 +7,7 @@
 #ifndef FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_
 #define FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "fpdfsdk/pdfwindow/PWL_Wnd.h"
 
 class CPWL_SBButton;
@@ -169,9 +170,9 @@
 
   PWL_SCROLLBAR_TYPE m_sbType;
   PWL_SCROLL_INFO m_OriginInfo;
-  CPWL_SBButton* m_pMinButton;
-  CPWL_SBButton* m_pMaxButton;
-  CPWL_SBButton* m_pPosButton;
+  CFX_UnownedPtr<CPWL_SBButton> m_pMinButton;
+  CFX_UnownedPtr<CPWL_SBButton> m_pMaxButton;
+  CFX_UnownedPtr<CPWL_SBButton> m_pPosButton;
   PWL_SCROLL_PRIVATEDATA m_sData;
   bool m_bMouseDown;
   bool m_bMinOrMax;
diff --git a/fpdfsdk/pdfwindow/PWL_Wnd.cpp b/fpdfsdk/pdfwindow/PWL_Wnd.cpp
index 5523c59..1db79b4 100644
--- a/fpdfsdk/pdfwindow/PWL_Wnd.cpp
+++ b/fpdfsdk/pdfwindow/PWL_Wnd.cpp
@@ -180,9 +180,9 @@
  private:
   std::vector<CPWL_Wnd*> m_aMousePath;
   std::vector<CPWL_Wnd*> m_aKeyboardPath;
-  CPWL_Wnd* m_pCreatedWnd;
-  CPWL_Wnd* m_pMainMouseWnd;
-  CPWL_Wnd* m_pMainKeyboardWnd;
+  CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
+  CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd;
+  CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
 };
 
 CPWL_Wnd::CPWL_Wnd()
@@ -594,10 +594,7 @@
 }
 
 CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
-  if (HasFlag(PWS_VSCROLL))
-    return m_pVScrollBar;
-
-  return nullptr;
+  return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
 }
 
 void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
@@ -885,7 +882,7 @@
 
 const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
   CPWL_MsgControl* pMsgCtrl = GetMsgControl();
-  return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd : nullptr;
+  return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
 }
 
 void CPWL_Wnd::EnableWindow(bool bEnable) {
diff --git a/fpdfsdk/pdfwindow/PWL_Wnd.h b/fpdfsdk/pdfwindow/PWL_Wnd.h
index ded003c..59de290 100644
--- a/fpdfsdk/pdfwindow/PWL_Wnd.h
+++ b/fpdfsdk/pdfwindow/PWL_Wnd.h
@@ -12,6 +12,7 @@
 
 #include "core/fpdfdoc/cpdf_formcontrol.h"
 #include "core/fxcrt/cfx_observable.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 #include "fpdfsdk/cfx_systemhandler.h"
 #include "fpdfsdk/cpdfsdk_widget.h"
@@ -224,8 +225,8 @@
 
  private:
   int32_t m_nTimerID;
-  CPWL_TimerHandler* m_pAttached;
-  CFX_SystemHandler* m_pSystemHandler;
+  CFX_UnownedPtr<CPWL_TimerHandler> m_pAttached;
+  CFX_UnownedPtr<CFX_SystemHandler> m_pSystemHandler;
 };
 
 class CPWL_TimerHandler {
@@ -398,7 +399,7 @@
 
   std::vector<CPWL_Wnd*> m_Children;
   PWL_CREATEPARAM m_sPrivateParam;
-  CPWL_ScrollBar* m_pVScrollBar;
+  CFX_UnownedPtr<CPWL_ScrollBar> m_pVScrollBar;
   CFX_FloatRect m_rcWindow;
   CFX_FloatRect m_rcClip;
   bool m_bCreated;
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
index 5c26188..ef83691 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
@@ -106,7 +106,7 @@
 std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Clone()
     const {
   auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>();
-  if (!temp->Init(m_field, &m_coefficients))
+  if (!temp->Init(m_field.Get(), &m_coefficients))
     return nullptr;
   return temp;
 }
@@ -133,7 +133,7 @@
         smallerCoefficients[j - lengthDiff], largerCoefficients[j]);
   }
   auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>();
-  if (!temp->Init(m_field, &sumDiff))
+  if (!temp->Init(m_field.Get(), &sumDiff))
     return nullptr;
   return temp;
 }
@@ -156,7 +156,7 @@
     }
   }
   auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>();
-  if (!temp->Init(m_field, &product))
+  if (!temp->Init(m_field.Get(), &product))
     return nullptr;
   return temp;
 }
@@ -174,7 +174,7 @@
     product[i] = m_field->Multiply(m_coefficients[i], scalar);
 
   auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>();
-  if (!temp->Init(m_field, &product))
+  if (!temp->Init(m_field.Get(), &product))
     return nullptr;
   return temp;
 }
@@ -193,7 +193,7 @@
     product[i] = m_field->Multiply(m_coefficients[i], coefficient);
 
   auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>();
-  if (!temp->Init(m_field, &product))
+  if (!temp->Init(m_field.Get(), &product))
     return nullptr;
   return temp;
 }
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
index ce8a572..f7aea2b 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
@@ -40,7 +40,7 @@
   std::unique_ptr<CBC_ReedSolomonGF256Poly> Clone() const;
 
  private:
-  CBC_ReedSolomonGF256* m_field;
+  CFX_UnownedPtr<CBC_ReedSolomonGF256> m_field;
   std::vector<int32_t> m_coefficients;
 };
 
diff --git a/fxbarcode/datamatrix/BC_EncoderContext.h b/fxbarcode/datamatrix/BC_EncoderContext.h
index 6cb2b42..21ea695 100644
--- a/fxbarcode/datamatrix/BC_EncoderContext.h
+++ b/fxbarcode/datamatrix/BC_EncoderContext.h
@@ -7,6 +7,7 @@
 #ifndef FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_
 #define FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/cfx_widestring.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
 
@@ -38,7 +39,7 @@
   CFX_WideString m_codewords;
   int32_t m_pos;
   int32_t m_newEncoding;
-  CBC_SymbolInfo* m_symbolInfo;
+  CFX_UnownedPtr<CBC_SymbolInfo> m_symbolInfo;
 
  private:
   int32_t getTotalMessageCharCount();
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index a7539e4..22cc095 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -197,7 +197,7 @@
   if (matrix) {
     affine_matrix.Concat(*matrix);
   }
-  device->DrawNormalText(str.GetLength(), pCharPos, m_pFont,
+  device->DrawNormalText(str.GetLength(), pCharPos, m_pFont.Get(),
                          static_cast<float>(iFontSize), &affine_matrix,
                          m_fontColor, FXTEXT_CLEARTYPE);
 }
@@ -224,7 +224,8 @@
   }
   int32_t iFontSize = (int32_t)fabs(m_fFontSize);
   int32_t iTextHeight = iFontSize + 1;
-  CalcTextInfo(str, charpos.data(), m_pFont, geWidth, iFontSize, charsLen);
+  CalcTextInfo(str, charpos.data(), m_pFont.Get(), geWidth, iFontSize,
+               charsLen);
   if (charsLen < 1)
     return true;
 
diff --git a/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h
index 3bd1b61..d81a3e0 100644
--- a/fxbarcode/oned/BC_OneDimWriter.h
+++ b/fxbarcode/oned/BC_OneDimWriter.h
@@ -10,6 +10,7 @@
 #include <memory>
 #include <vector>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxge/cfx_renderdevice.h"
 #include "fxbarcode/BC_Library.h"
 #include "fxbarcode/BC_Writer.h"
@@ -86,7 +87,7 @@
   bool m_bPrintChecksum;
   int32_t m_iDataLenth;
   bool m_bCalcChecksum;
-  CFX_Font* m_pFont;
+  CFX_UnownedPtr<CFX_Font> m_pFont;
   float m_fFontSize;
   int32_t m_iFontStyle;
   uint32_t m_fontColor;
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index bae43b4..0e4bab9 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -192,7 +192,7 @@
   iLen = tempStr.GetLength();
   strWidth = (int32_t)(strWidth * m_outputHScale);
 
-  CalcTextInfo(tempStr, &charpos[1], m_pFont, (float)strWidth, iFontSize,
+  CalcTextInfo(tempStr, &charpos[1], m_pFont.Get(), (float)strWidth, iFontSize,
                blank);
   {
     CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
@@ -200,13 +200,13 @@
                               (float)(m_Height - iTextHeight) + iFontSize);
     if (matrix)
       affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, &charpos[1], m_pFont,
+    device->DrawNormalText(iLen, &charpos[1], m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Mid(7, 6);
   iLen = tempStr.GetLength();
-  CalcTextInfo(tempStr, &charpos[7], m_pFont, (float)strWidth, iFontSize,
+  CalcTextInfo(tempStr, &charpos[7], m_pFont.Get(), (float)strWidth, iFontSize,
                blank);
   {
     CFX_Matrix affine_matrix1(
@@ -215,7 +215,7 @@
         (float)(m_Height - iTextHeight + iFontSize));
     if (matrix)
       affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, &charpos[7], m_pFont,
+    device->DrawNormalText(iLen, &charpos[7], m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
@@ -224,14 +224,14 @@
   strWidth = multiple * 7;
   strWidth = (int32_t)(strWidth * m_outputHScale);
 
-  CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize,
-               blank);
+  CalcTextInfo(tempStr, charpos.data(), m_pFont.Get(), (float)strWidth,
+               iFontSize, blank);
   {
     CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0,
                               (float)(m_Height - iTextHeight + iFontSize));
     if (matrix)
       affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, charpos.data(), m_pFont,
+    device->DrawNormalText(iLen, charpos.data(), m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index 49d77b7..f891c08 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -184,20 +184,20 @@
   device->FillRect(&re, m_backgroundColor);
   strWidth = (int32_t)(strWidth * m_outputHScale);
 
-  CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize,
-               blank);
+  CalcTextInfo(tempStr, charpos.data(), m_pFont.Get(), (float)strWidth,
+               iFontSize, blank);
   {
     CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
                               (float)leftPosition * m_outputHScale,
                               (float)(m_Height - iTextHeight + iFontSize));
     affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, charpos.data(), m_pFont,
+    device->DrawNormalText(iLen, charpos.data(), m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Mid(4, 4);
   iLen = tempStr.GetLength();
-  CalcTextInfo(tempStr, &charpos[4], m_pFont, (float)strWidth, iFontSize,
+  CalcTextInfo(tempStr, &charpos[4], m_pFont.Get(), (float)strWidth, iFontSize,
                blank);
   {
     CFX_Matrix affine_matrix1(
@@ -206,7 +206,7 @@
         (float)(m_Height - iTextHeight + iFontSize));
     if (matrix)
       affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, &charpos[4], m_pFont,
+    device->DrawNormalText(iLen, &charpos[4], m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index 614268e..78ada17 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -158,20 +158,20 @@
   device->FillRect(&re, m_backgroundColor);
   strWidth = strWidth * m_outputHScale;
 
-  CalcTextInfo(tempStr, &charpos[1], m_pFont, strWidth, iFontSize, blank);
+  CalcTextInfo(tempStr, &charpos[1], m_pFont.Get(), strWidth, iFontSize, blank);
   {
     CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
                               (float)leftPosition * m_outputHScale,
                               (float)(m_Height - iTextHeight + iFontSize));
     if (matrix)
       affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, &charpos[1], m_pFont,
+    device->DrawNormalText(iLen, &charpos[1], m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Mid(6, 5);
   iLen = tempStr.GetLength();
-  CalcTextInfo(tempStr, &charpos[6], m_pFont, strWidth, iFontSize, blank);
+  CalcTextInfo(tempStr, &charpos[6], m_pFont.Get(), strWidth, iFontSize, blank);
   {
     CFX_Matrix affine_matrix1(
         1.0, 0.0, 0.0, -1.0,
@@ -179,7 +179,7 @@
         (float)(m_Height - iTextHeight + iFontSize));
     if (matrix)
       affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, &charpos[6], m_pFont,
+    device->DrawNormalText(iLen, &charpos[6], m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
@@ -188,19 +188,21 @@
   strWidth = (float)multiple * 7;
   strWidth = strWidth * m_outputHScale;
 
-  CalcTextInfo(tempStr, charpos.data(), m_pFont, strWidth, iFontSize, blank);
+  CalcTextInfo(tempStr, charpos.data(), m_pFont.Get(), strWidth, iFontSize,
+               blank);
   {
     CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0,
                               (float)(m_Height - iTextHeight + iFontSize));
     if (matrix)
       affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, charpos.data(), m_pFont,
+    device->DrawNormalText(iLen, charpos.data(), m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Mid(11, 1);
   iLen = tempStr.GetLength();
-  CalcTextInfo(tempStr, &charpos[11], m_pFont, strWidth, iFontSize, blank);
+  CalcTextInfo(tempStr, &charpos[11], m_pFont.Get(), strWidth, iFontSize,
+               blank);
   {
     CFX_Matrix affine_matrix1(
         1.0, 0.0, 0.0, -1.0,
@@ -208,7 +210,7 @@
         (float)(m_Height - iTextHeight + iFontSize));
     if (matrix)
       affine_matrix1.Concat(*matrix);
-    device->DrawNormalText(iLen, &charpos[11], m_pFont,
+    device->DrawNormalText(iLen, &charpos[11], m_pFont.Get(),
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
diff --git a/fxbarcode/qrcode/BC_QRCoder.cpp b/fxbarcode/qrcode/BC_QRCoder.cpp
index e3ac763..b0a24fa 100644
--- a/fxbarcode/qrcode/BC_QRCoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoder.cpp
@@ -42,11 +42,11 @@
 CBC_QRCoder::~CBC_QRCoder() {}
 
 CBC_QRCoderMode* CBC_QRCoder::GetMode() const {
-  return m_mode;
+  return m_mode.Get();
 }
 
 const CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const {
-  return m_ecLevel;
+  return m_ecLevel.Get();
 }
 
 int32_t CBC_QRCoder::GetVersion() const {
diff --git a/fxbarcode/qrcode/BC_QRCoder.h b/fxbarcode/qrcode/BC_QRCoder.h
index adeae6c..fe34b52 100644
--- a/fxbarcode/qrcode/BC_QRCoder.h
+++ b/fxbarcode/qrcode/BC_QRCoder.h
@@ -9,6 +9,8 @@
 
 #include <memory>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
+
 class CBC_QRCoderErrorCorrectionLevel;
 class CBC_QRCoderMode;
 class CBC_CommonByteMatrix;
@@ -48,8 +50,8 @@
   void SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix);
 
  private:
-  CBC_QRCoderMode* m_mode;
-  const CBC_QRCoderErrorCorrectionLevel* m_ecLevel;
+  CFX_UnownedPtr<CBC_QRCoderMode> m_mode;
+  CFX_UnownedPtr<const CBC_QRCoderErrorCorrectionLevel> m_ecLevel;
   int32_t m_version;
   int32_t m_matrixWidth;
   int32_t m_maskPattern;
diff --git a/fxjs/cfxjse_arguments.cpp b/fxjs/cfxjse_arguments.cpp
index f406ba3..363f39c 100644
--- a/fxjs/cfxjse_arguments.cpp
+++ b/fxjs/cfxjse_arguments.cpp
@@ -10,6 +10,13 @@
 #include "fxjs/cfxjse_value.h"
 #include "third_party/base/ptr_util.h"
 
+CFXJSE_Arguments::CFXJSE_Arguments(
+    const v8::FunctionCallbackInfo<v8::Value>* pInfo,
+    CFXJSE_Value* pRetValue)
+    : m_pInfo(pInfo), m_pRetValue(pRetValue) {}
+
+CFXJSE_Arguments::~CFXJSE_Arguments() {}
+
 int32_t CFXJSE_Arguments::GetLength() const {
   return m_pInfo->Length();
 }
@@ -47,6 +54,6 @@
   return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass);
 }
 
-CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() {
-  return m_pRetValue;
+CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() const {
+  return m_pRetValue.Get();
 }
diff --git a/fxjs/cfxjse_arguments.h b/fxjs/cfxjse_arguments.h
index beaf152..9317d70 100644
--- a/fxjs/cfxjse_arguments.h
+++ b/fxjs/cfxjse_arguments.h
@@ -9,14 +9,15 @@
 
 #include <memory>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "fxjs/cfxjse_class.h"
 #include "fxjs/fxjse.h"
 
 class CFXJSE_Arguments {
  public:
   CFXJSE_Arguments(const v8::FunctionCallbackInfo<v8::Value>* pInfo,
-                   CFXJSE_Value* pRetValue)
-      : m_pInfo(pInfo), m_pRetValue(pRetValue) {}
+                   CFXJSE_Value* pRetValue);
+  ~CFXJSE_Arguments();
 
   int32_t GetLength() const;
   std::unique_ptr<CFXJSE_Value> GetValue(int32_t index) const;
@@ -26,11 +27,11 @@
   CFX_ByteString GetUTF8String(int32_t index) const;
   CFXJSE_HostObject* GetObject(int32_t index,
                                CFXJSE_Class* pClass = nullptr) const;
-  CFXJSE_Value* GetReturnValue();
+  CFXJSE_Value* GetReturnValue() const;
 
  private:
   const v8::FunctionCallbackInfo<v8::Value>* m_pInfo;
-  CFXJSE_Value* m_pRetValue;
+  CFX_UnownedPtr<CFXJSE_Value> m_pRetValue;
 };
 
 #endif  // FXJS_CFXJSE_ARGUMENTS_H_
diff --git a/fxjs/cfxjse_class.h b/fxjs/cfxjse_class.h
index 0435494..c3a5c84 100644
--- a/fxjs/cfxjse_class.h
+++ b/fxjs/cfxjse_class.h
@@ -7,6 +7,7 @@
 #ifndef FXJS_CFXJSE_CLASS_H_
 #define FXJS_CFXJSE_CLASS_H_
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "fxjs/fxjse.h"
 #include "v8/include/v8.h"
 
@@ -27,13 +28,13 @@
   explicit CFXJSE_Class(CFXJSE_Context* lpContext);
   ~CFXJSE_Class();
 
-  CFXJSE_Context* GetContext() const { return m_pContext; }
+  CFXJSE_Context* GetContext() const { return m_pContext.Get(); }
   v8::Global<v8::FunctionTemplate>& GetTemplate() { return m_hTemplate; }
 
  protected:
   CFX_ByteString m_szClassName;
-  const FXJSE_CLASS_DESCRIPTOR* m_lpClassDefinition;
-  CFXJSE_Context* m_pContext;
+  CFX_UnownedPtr<const FXJSE_CLASS_DESCRIPTOR> m_lpClassDefinition;
+  CFX_UnownedPtr<CFXJSE_Context> m_pContext;
   v8::Global<v8::FunctionTemplate> m_hTemplate;
   friend class CFXJSE_Context;
   friend class CFXJSE_Value;
diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp
index 8696cee..40882ba 100644
--- a/fxjs/cfxjse_context.cpp
+++ b/fxjs/cfxjse_context.cpp
@@ -68,7 +68,7 @@
   void* operator new(size_t size) = delete;
   void operator delete(void*, size_t) = delete;
 
-  CFXJSE_Context* m_context;
+  CFX_UnownedPtr<CFXJSE_Context> m_context;
   CFXJSE_ScopeUtil_IsolateHandle m_parent;
   v8::Context::Scope m_cscope;
 };