summaryrefslogtreecommitdiff
path: root/xfa/fgas/crt
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-04 15:43:59 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-04 15:43:59 -0700
commitcddf8253692d3beaa97a502c8b60c1d18f81664a (patch)
treebaa5b2456a1bdfec97fa97be2ef07eb3295a82d7 /xfa/fgas/crt
parent32e693fe13105fab5baf81b334e932fce62d89b5 (diff)
downloadpdfium-cddf8253692d3beaa97a502c8b60c1d18f81664a.tar.xz
Use smart pointers for class owned pointers under xfa/fde
Use smart pointer to replace raw pointer type for class owned member variables so that memory management will be easier. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2208423002
Diffstat (limited to 'xfa/fgas/crt')
-rw-r--r--xfa/fgas/crt/fgas_memory.cpp23
-rw-r--r--xfa/fgas/crt/fgas_memory.h8
2 files changed, 18 insertions, 13 deletions
diff --git a/xfa/fgas/crt/fgas_memory.cpp b/xfa/fgas/crt/fgas_memory.cpp
index d218f42aa4..e587f5a5b0 100644
--- a/xfa/fgas/crt/fgas_memory.cpp
+++ b/xfa/fgas/crt/fgas_memory.cpp
@@ -27,10 +27,11 @@ class CFX_DefStore : public IFX_MemoryAllocator, public CFX_Target {
} // namespace
-IFX_MemoryAllocator* IFX_MemoryAllocator::Create(FX_ALLOCTYPE eType,
- size_t chunkSize,
- size_t blockSize) {
- return new CFX_DefStore();
+std::unique_ptr<IFX_MemoryAllocator> IFX_MemoryAllocator::Create(
+ FX_ALLOCTYPE eType,
+ size_t chunkSize,
+ size_t blockSize) {
+ return std::unique_ptr<IFX_MemoryAllocator>(new CFX_DefStore());
}
#else // MEMORY_TOOL_REPLACES_ALLOCATOR
@@ -88,17 +89,19 @@ class CFX_FixedStore : public IFX_MemoryAllocator, public CFX_Target {
#define FX_4BYTEALIGN(size) (((size) + 3) & ~3)
-IFX_MemoryAllocator* IFX_MemoryAllocator::Create(FX_ALLOCTYPE eType,
- size_t chunkSize,
- size_t blockSize) {
+std::unique_ptr<IFX_MemoryAllocator> IFX_MemoryAllocator::Create(
+ FX_ALLOCTYPE eType,
+ size_t chunkSize,
+ size_t blockSize) {
switch (eType) {
case FX_ALLOCTYPE_Static:
- return new CFX_StaticStore(chunkSize);
+ return std::unique_ptr<IFX_MemoryAllocator>(
+ new CFX_StaticStore(chunkSize));
case FX_ALLOCTYPE_Fixed:
- return new CFX_FixedStore(blockSize, chunkSize);
+ return std::unique_ptr<IFX_MemoryAllocator>(new CFX_FixedStore(blockSize, chunkSize);
default:
ASSERT(0);
- return nullptr;
+ return std::unique_ptr<IFX_MemoryAllocator>();
}
}
diff --git a/xfa/fgas/crt/fgas_memory.h b/xfa/fgas/crt/fgas_memory.h
index a83933c7a5..1034c417d7 100644
--- a/xfa/fgas/crt/fgas_memory.h
+++ b/xfa/fgas/crt/fgas_memory.h
@@ -7,6 +7,8 @@
#ifndef XFA_FGAS_CRT_FGAS_MEMORY_H_
#define XFA_FGAS_CRT_FGAS_MEMORY_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_memory.h"
#include "core/fxcrt/include/fx_system.h"
@@ -21,9 +23,9 @@ class IFX_MemoryAllocator {
virtual void* Alloc(size_t size) = 0;
virtual void Free(void* pBlock) = 0;
- static IFX_MemoryAllocator* Create(FX_ALLOCTYPE eType,
- size_t chunkSize,
- size_t blockSize);
+ static std::unique_ptr<IFX_MemoryAllocator> Create(FX_ALLOCTYPE eType,
+ size_t chunkSize,
+ size_t blockSize);
};
class CFX_Target {