summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_memory.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-17 16:42:32 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-17 16:42:32 +0000
commit23b2d61fdd1f78679c6bb375bb9dde666cf7cc3f (patch)
tree338a25867fd14bbd9e6b45137a9095bfc661cead /core/fxcrt/fx_memory.cpp
parenta358d622339d022e3723525141900365caf55ca1 (diff)
downloadpdfium-23b2d61fdd1f78679c6bb375bb9dde666cf7cc3f.tar.xz
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 <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_memory.cpp')
-rw-r--r--core/fxcrt/fx_memory.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/core/fxcrt/fx_memory.cpp b/core/fxcrt/fx_memory.cpp
index 73d894aefa..8c50f23aa4 100644
--- a/core/fxcrt/fx_memory.cpp
+++ b/core/fxcrt/fx_memory.cpp
@@ -11,25 +11,36 @@
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/debug/alias.h"
-pdfium::base::PartitionAllocatorGeneric gArrayBufferPartitionAllocator;
-pdfium::base::PartitionAllocatorGeneric gGeneralPartitionAllocator;
-pdfium::base::PartitionAllocatorGeneric gStringPartitionAllocator;
+pdfium::base::PartitionAllocatorGeneric& GetArrayBufferPartitionAllocator() {
+ static pdfium::base::PartitionAllocatorGeneric s_array_buffer_allocator;
+ return s_array_buffer_allocator;
+}
+
+pdfium::base::PartitionAllocatorGeneric& GetGeneralPartitionAllocator() {
+ static pdfium::base::PartitionAllocatorGeneric s_general_allocator;
+ return s_general_allocator;
+}
+
+pdfium::base::PartitionAllocatorGeneric& GetStringPartitionAllocator() {
+ static pdfium::base::PartitionAllocatorGeneric s_string_allocator;
+ return s_string_allocator;
+}
void FXMEM_InitializePartitionAlloc() {
- static bool s_gPartitionAllocatorsInitialized = false;
- if (!s_gPartitionAllocatorsInitialized) {
+ static bool s_partition_allocators_initialized = false;
+ if (!s_partition_allocators_initialized) {
pdfium::base::PartitionAllocGlobalInit(FX_OutOfMemoryTerminate);
- gArrayBufferPartitionAllocator.init();
- gGeneralPartitionAllocator.init();
- gStringPartitionAllocator.init();
- s_gPartitionAllocatorsInitialized = true;
+ GetArrayBufferPartitionAllocator().init();
+ GetGeneralPartitionAllocator().init();
+ GetStringPartitionAllocator().init();
+ s_partition_allocators_initialized = true;
}
}
void* FXMEM_DefaultAlloc(size_t byte_size) {
return pdfium::base::PartitionAllocGenericFlags(
- gGeneralPartitionAllocator.root(), pdfium::base::PartitionAllocReturnNull,
- byte_size, "GeneralPartition");
+ GetGeneralPartitionAllocator().root(),
+ pdfium::base::PartitionAllocReturnNull, byte_size, "GeneralPartition");
}
void* FXMEM_DefaultCalloc(size_t num_elems, size_t byte_size) {
@@ -38,8 +49,9 @@ void* FXMEM_DefaultCalloc(size_t num_elems, size_t byte_size) {
void* FXMEM_DefaultRealloc(void* pointer, size_t new_size) {
return pdfium::base::PartitionReallocGenericFlags(
- gGeneralPartitionAllocator.root(), pdfium::base::PartitionAllocReturnNull,
- pointer, new_size, "GeneralPartition");
+ GetGeneralPartitionAllocator().root(),
+ pdfium::base::PartitionAllocReturnNull, pointer, new_size,
+ "GeneralPartition");
}
void FXMEM_DefaultFree(void* pointer) {