| Index: third_party/tcmalloc/chromium/src/tcmalloc.cc
|
| diff --git a/third_party/tcmalloc/chromium/src/tcmalloc.cc b/third_party/tcmalloc/chromium/src/tcmalloc.cc
|
| index 2ff2a3b47ed6f4c82d0de1446d8eaac4318ea36d..026e6d35761414b248a07c2113241853be40f9e6 100644
|
| --- a/third_party/tcmalloc/chromium/src/tcmalloc.cc
|
| +++ b/third_party/tcmalloc/chromium/src/tcmalloc.cc
|
| @@ -1078,27 +1078,31 @@ inline void* do_malloc(size_t size) {
|
|
|
| // The following call forces module initialization
|
| ThreadCache* heap = ThreadCache::GetCache();
|
| - if (size <= kMaxSize) {
|
| - size_t cl = Static::sizemap()->SizeClass(size);
|
| - size = Static::sizemap()->class_to_size(cl);
|
| -
|
| - // TODO(jar): If this has any detectable performance impact, it can be
|
| - // optimized by only tallying sizes if the profiler was activated to recall
|
| - // these tallies. I don't think this is performance critical, but we really
|
| - // should measure it.
|
| - heap->AddToByteAllocatedTotal(size); // Chromium profiling.
|
| -
|
| - if ((FLAGS_tcmalloc_sample_parameter > 0) && heap->SampleAllocation(size)) {
|
| - ret = DoSampledAllocation(size);
|
| - MarkAllocatedRegion(ret);
|
| + // First, check if our security policy allows this size.
|
| + if (tcmalloc::IsAllocSizePermitted(size)) {
|
| + if (size <= kMaxSize) {
|
| + size_t cl = Static::sizemap()->SizeClass(size);
|
| + size = Static::sizemap()->class_to_size(cl);
|
| +
|
| + // TODO(jar): If this has any detectable performance impact, it can be
|
| + // optimized by only tallying sizes if the profiler was activated to
|
| + // recall these tallies. I don't think this is performance critical, but
|
| + // we really should measure it.
|
| + heap->AddToByteAllocatedTotal(size); // Chromium profiling.
|
| +
|
| + if ((FLAGS_tcmalloc_sample_parameter > 0) &&
|
| + heap->SampleAllocation(size)) {
|
| + ret = DoSampledAllocation(size);
|
| + MarkAllocatedRegion(ret);
|
| + } else {
|
| + // The common case, and also the simplest. This just pops the
|
| + // size-appropriate freelist, after replenishing it if it's empty.
|
| + ret = CheckMallocResult(heap->Allocate(size, cl));
|
| + }
|
| } else {
|
| - // The common case, and also the simplest. This just pops the
|
| - // size-appropriate freelist, after replenishing it if it's empty.
|
| - ret = CheckMallocResult(heap->Allocate(size, cl));
|
| + ret = do_malloc_pages(heap, size);
|
| + MarkAllocatedRegion(ret);
|
| }
|
| - } else {
|
| - ret = do_malloc_pages(heap, size);
|
| - MarkAllocatedRegion(ret);
|
| }
|
| if (ret == NULL) errno = ENOMEM;
|
| return ret;
|
| @@ -1233,8 +1237,8 @@ inline void* do_realloc_with_callback(
|
| // . If we need to grow, grow to max(new_size, old_size * 1.X)
|
| // . Don't shrink unless new_size < old_size * 0.Y
|
| // X and Y trade-off time for wasted space. For now we do 1.25 and 0.5.
|
| - const int lower_bound_to_grow = old_size + old_size / 4;
|
| - const int upper_bound_to_shrink = old_size / 2;
|
| + const size_t lower_bound_to_grow = old_size + old_size / 4;
|
| + const size_t upper_bound_to_shrink = old_size / 2;
|
| if ((new_size > old_size) || (new_size < upper_bound_to_shrink)) {
|
| // Need to reallocate.
|
| void* new_ptr = NULL;
|
|
|