From 23b2d61fdd1f78679c6bb375bb9dde666cf7cc3f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 17 Oct 2018 16:42:32 +0000 Subject: Fix the static initialization order problem for PartitionAlloc. Inside fx_memory.cpp, the PartitionAllocatorGeneric objects are globals, so their initialization order is not well defined. BUG=chromium:896117 Change-Id: If4a345d6d7549b0e99a055859eaa67d5ec32c788 Reviewed-on: https://pdfium-review.googlesource.com/c/44170 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- core/fxcrt/fx_memory.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'core/fxcrt/fx_memory.h') diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h index 5ad66e710d..068f121285 100644 --- a/core/fxcrt/fx_memory.h +++ b/core/fxcrt/fx_memory.h @@ -30,9 +30,9 @@ void FXMEM_DefaultFree(void* pointer); #include "core/fxcrt/fx_safe_types.h" #include "third_party/base/allocator/partition_allocator/partition_alloc.h" -extern pdfium::base::PartitionAllocatorGeneric gArrayBufferPartitionAllocator; -extern pdfium::base::PartitionAllocatorGeneric gGeneralPartitionAllocator; -extern pdfium::base::PartitionAllocatorGeneric gStringPartitionAllocator; +pdfium::base::PartitionAllocatorGeneric& GetArrayBufferPartitionAllocator(); +pdfium::base::PartitionAllocatorGeneric& GetGeneralPartitionAllocator(); +pdfium::base::PartitionAllocatorGeneric& GetStringPartitionAllocator(); void FXMEM_InitializePartitionAlloc(); NEVER_INLINE void FX_OutOfMemoryTerminate(); @@ -46,7 +46,7 @@ inline void* FX_SafeAlloc(size_t num_members, size_t member_size) { constexpr int kFlags = pdfium::base::PartitionAllocReturnNull | pdfium::base::PartitionAllocZeroFill; return pdfium::base::PartitionAllocGenericFlags( - gGeneralPartitionAllocator.root(), kFlags, total.ValueOrDie(), + GetGeneralPartitionAllocator().root(), kFlags, total.ValueOrDie(), "GeneralPartition"); } @@ -57,8 +57,9 @@ inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { return nullptr; return pdfium::base::PartitionReallocGenericFlags( - gGeneralPartitionAllocator.root(), pdfium::base::PartitionAllocReturnNull, - ptr, size.ValueOrDie(), "GeneralPartition"); + GetGeneralPartitionAllocator().root(), + pdfium::base::PartitionAllocReturnNull, ptr, size.ValueOrDie(), + "GeneralPartition"); } inline void* FX_AllocOrDie(size_t num_members, size_t member_size) { -- cgit v1.2.3