From e4b035b722ad69d4a4357c54cd3c9f1f8574b067 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Sun, 26 Mar 2017 15:48:34 -0700 Subject: Use PartitionAlloc for JavaScript ArrayBuffers and strings. BUG=pdfium:681 Change-Id: I5073d80d9bd623b73e578d5ba2226c39c371bab0 Reviewed-on: https://pdfium-review.googlesource.com/3097 Commit-Queue: Chris Palmer Reviewed-by: Tom Sepez --- core/fxcrt/cfx_string_data_template.h | 5 +++-- core/fxcrt/fx_basic_memmgr.cpp | 3 +++ core/fxcrt/fx_memory.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/cfx_string_data_template.h b/core/fxcrt/cfx_string_data_template.h index 2e87a811a5..33013fde33 100644 --- a/core/fxcrt/cfx_string_data_template.h +++ b/core/fxcrt/cfx_string_data_template.h @@ -35,7 +35,8 @@ class CFX_StringDataTemplate { int usableLen = (totalSize - overhead) / sizeof(CharType); ASSERT(usableLen >= nLen); - void* pData = FX_Alloc(uint8_t, totalSize); + void* pData = pdfium::base::PartitionAllocGeneric( + gStringPartitionAllocator.root(), totalSize, "CFX_StringDataTemplate"); return new (pData) CFX_StringDataTemplate(nLen, usableLen); } @@ -54,7 +55,7 @@ class CFX_StringDataTemplate { void Retain() { ++m_nRefs; } void Release() { if (--m_nRefs <= 0) - FX_Free(this); + pdfium::base::PartitionFree(this); } bool CanOperateInPlace(FX_STRSIZE nTotalLen) const { diff --git a/core/fxcrt/fx_basic_memmgr.cpp b/core/fxcrt/fx_basic_memmgr.cpp index 927b994b5f..06568c04ad 100644 --- a/core/fxcrt/fx_basic_memmgr.cpp +++ b/core/fxcrt/fx_basic_memmgr.cpp @@ -8,6 +8,9 @@ #include "core/fxcrt/fx_memory.h" +pdfium::base::PartitionAllocatorGeneric gArrayBufferPartitionAllocator; +pdfium::base::PartitionAllocatorGeneric gStringPartitionAllocator; + void* FXMEM_DefaultAlloc(size_t byte_size, int flags) { return (void*)malloc(byte_size); } diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h index 0ad28ce896..c4d619efab 100644 --- a/core/fxcrt/fx_memory.h +++ b/core/fxcrt/fx_memory.h @@ -26,6 +26,11 @@ void FXMEM_DefaultFree(void* pointer, int flags); #include #include +#include "third_party/base/allocator/partition_allocator/partition_alloc.h" + +extern pdfium::base::PartitionAllocatorGeneric gArrayBufferPartitionAllocator; +extern pdfium::base::PartitionAllocatorGeneric gStringPartitionAllocator; + NEVER_INLINE void FX_OutOfMemoryTerminate(); inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { -- cgit v1.2.3