#include "sanitizer_common/sanitizer_internal_defs.h"
#include "sanitizer_common/sanitizer_stackdepot.h"
#include "sanitizer_common/sanitizer_stacktrace.h"
+#include "sanitizer_common/sanitizer_allocator_internal.h"
#include "lsan_common.h"
extern "C" void *memset(void *ptr, int value, uptr num);
SecondaryAllocator> Allocator;
static Allocator allocator;
-static THREADLOCAL AllocatorCache allocator_cache;
-AllocatorCache *GetAllocatorCache() { return &allocator_cache; }
+static THREADLOCAL AllocatorCache *allocator_cache;
+AllocatorCache *GetAllocatorCache() {
+ if (UNLIKELY(allocator_cache == nullptr)) {
+ // We will not release the memory because the library is not unloaded.
+ allocator_cache = (AllocatorCache *)InternalAlloc(sizeof(*allocator_cache));
+ *allocator_cache = AllocatorCache();
+ }
+ return allocator_cache;
+}
void InitializeAllocator() {
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);