summaryrefslogtreecommitdiff
path: root/libsanitizer/lsan/lsan_allocator.cpp
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2019-11-07 10:33:54 +0100
committerMartin Liska <marxin@gcc.gnu.org>2019-11-07 09:33:54 +0000
commitcb7dc4da4ccc475675b5aec6a08d3e8c0a1761e4 (patch)
tree610840af295a13e6f4c2e87e7bfe52a4723ca534 /libsanitizer/lsan/lsan_allocator.cpp
parent29f3def30844dd13e79972fa03a50af68120f7ac (diff)
Libsanitizer: merge from trunk
2019-11-07 Martin Liska <mliska@suse.cz> * merge.sh: Update to use llvm-project git repository. * all source files: Merge from upstream 82588e05cc32bb30807e480abd4e689b0dee132a. From-SVN: r277909
Diffstat (limited to 'libsanitizer/lsan/lsan_allocator.cpp')
-rw-r--r--libsanitizer/lsan/lsan_allocator.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/libsanitizer/lsan/lsan_allocator.cpp b/libsanitizer/lsan/lsan_allocator.cpp
index 66a81ab350e..d86c3921395 100644
--- a/libsanitizer/lsan/lsan_allocator.cpp
+++ b/libsanitizer/lsan/lsan_allocator.cpp
@@ -36,10 +36,17 @@ static const uptr kMaxAllowedMallocSize = 8UL << 30;
static Allocator allocator;
+static uptr max_malloc_size;
+
void InitializeAllocator() {
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
allocator.InitLinkerInitialized(
common_flags()->allocator_release_to_os_interval_ms);
+ if (common_flags()->max_allocation_size_mb)
+ max_malloc_size = Min(common_flags()->max_allocation_size_mb << 20,
+ kMaxAllowedMallocSize);
+ else
+ max_malloc_size = kMaxAllowedMallocSize;
}
void AllocatorThreadFinish() {
@@ -72,14 +79,14 @@ static void *ReportAllocationSizeTooBig(uptr size, const StackTrace &stack) {
Report("WARNING: LeakSanitizer failed to allocate 0x%zx bytes\n", size);
return nullptr;
}
- ReportAllocationSizeTooBig(size, kMaxAllowedMallocSize, &stack);
+ ReportAllocationSizeTooBig(size, max_malloc_size, &stack);
}
void *Allocate(const StackTrace &stack, uptr size, uptr alignment,
bool cleared) {
if (size == 0)
size = 1;
- if (size > kMaxAllowedMallocSize)
+ if (size > max_malloc_size)
return ReportAllocationSizeTooBig(size, stack);
void *p = allocator.Allocate(GetAllocatorCache(), size, alignment);
if (UNLIKELY(!p)) {
@@ -117,7 +124,7 @@ void Deallocate(void *p) {
void *Reallocate(const StackTrace &stack, void *p, uptr new_size,
uptr alignment) {
RegisterDeallocation(p);
- if (new_size > kMaxAllowedMallocSize) {
+ if (new_size > max_malloc_size) {
allocator.Deallocate(GetAllocatorCache(), p);
return ReportAllocationSizeTooBig(new_size, stack);
}