Pass unique_ptr<> to CFX_MemoryStream constructor

Proves we own the memory that the class will eventually free.

Change-Id: Ie9523da8db738e7478a1c73e3e1a6b24aed38442
Reviewed-on: https://pdfium-review.googlesource.com/41290
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_object_stream.cpp b/core/fpdfapi/parser/cpdf_object_stream.cpp
index d6b3d36..7e4b4ae 100644
--- a/core/fpdfapi/parser/cpdf_object_stream.cpp
+++ b/core/fpdfapi/parser/cpdf_object_stream.cpp
@@ -97,7 +97,7 @@
     stream_acc->LoadAllDataFiltered();
     const uint32_t data_size = stream_acc->GetSize();
     data_stream_ = pdfium::MakeRetain<CFX_MemoryStream>(
-        stream_acc->DetachData().release(), data_size);
+        stream_acc->DetachData(), data_size);
   }
 
   CPDF_SyntaxParser syntax(data_stream_);
diff --git a/core/fxcrt/cfx_memorystream.cpp b/core/fxcrt/cfx_memorystream.cpp
index d64d2a0..ac04dcc 100644
--- a/core/fxcrt/cfx_memorystream.cpp
+++ b/core/fxcrt/cfx_memorystream.cpp
@@ -7,13 +7,16 @@
 #include "core/fxcrt/cfx_memorystream.h"
 
 #include <algorithm>
+#include <utility>
 
 #include "core/fxcrt/fx_safe_types.h"
 
 CFX_MemoryStream::CFX_MemoryStream() : m_nTotalSize(0), m_nCurSize(0) {}
 
-CFX_MemoryStream::CFX_MemoryStream(uint8_t* pBuffer, size_t nSize)
-    : m_data(pBuffer), m_nTotalSize(nSize), m_nCurSize(nSize) {}
+CFX_MemoryStream::CFX_MemoryStream(
+    std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer,
+    size_t nSize)
+    : m_data(std::move(pBuffer)), m_nTotalSize(nSize), m_nCurSize(nSize) {}
 
 CFX_MemoryStream::~CFX_MemoryStream() = default;
 
diff --git a/core/fxcrt/cfx_memorystream.h b/core/fxcrt/cfx_memorystream.h
index 47e4912..99e39a8 100644
--- a/core/fxcrt/cfx_memorystream.h
+++ b/core/fxcrt/cfx_memorystream.h
@@ -31,9 +31,8 @@
 
  private:
   CFX_MemoryStream();
-
-  // Takes ownership of |pBuffer|.
-  CFX_MemoryStream(uint8_t* pBuffer, size_t nSize);
+  CFX_MemoryStream(std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer,
+                   size_t nSize);
   ~CFX_MemoryStream() override;
 
   std::unique_ptr<uint8_t, FxFreeDeleter> m_data;
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index f6b168c..d0a6127 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -626,10 +626,11 @@
   if (dwFileSize == 0)
     return nullptr;
 
-  uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1);
-  dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize);
-
-  return pdfium::MakeRetain<CFX_MemoryStream>(pBuffer, dwFileSize);
+  std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer(
+      FX_Alloc(uint8_t, dwFileSize + 1));
+  dwFileSize =
+      pSystemFontInfo->GetFontData(hFont, 0, pBuffer.get(), dwFileSize);
+  return pdfium::MakeRetain<CFX_MemoryStream>(std::move(pBuffer), dwFileSize);
 }
 
 RetainPtr<IFX_SeekableReadStream> CFGAS_FontMgr::CreateFontStream(