Chromium Code Reviews| Index: base/trace_event/heap_profiler_allocation_register.cc |
| diff --git a/base/trace_event/heap_profiler_allocation_register.cc b/base/trace_event/heap_profiler_allocation_register.cc |
| index 63d40611a6f6dcef24d2f524ff60ebf1994dfe62..f9868ea7a803b8aec24b78f16c99707a3c172970 100644 |
| --- a/base/trace_event/heap_profiler_allocation_register.cc |
| +++ b/base/trace_event/heap_profiler_allocation_register.cc |
| @@ -81,12 +81,12 @@ AllocationRegister::AllocationRegister(size_t allocation_capacity, |
| AllocationRegister::~AllocationRegister() { |
| } |
| -void AllocationRegister::Insert(const void* address, |
| +bool AllocationRegister::Insert(const void* address, |
| size_t size, |
| const AllocationContext& context) { |
| DCHECK(address != nullptr); |
| if (size == 0) { |
| - return; |
| + return false; |
| } |
| AllocationInfo info = { |
| @@ -97,12 +97,15 @@ void AllocationRegister::Insert(const void* address, |
| // Try to insert the allocation. |
| auto index_and_flag = allocations_.Insert(address, info); |
| - if (!index_and_flag.second) { |
| + if (!index_and_flag.second && |
| + index_and_flag.first != AllocationMap::kInvalidKVIndex) { |
| // |address| is already there - overwrite the allocation info. |
| auto& old_info = allocations_.Get(index_and_flag.first).second; |
| RemoveBacktrace(old_info.backtrace_index); |
| old_info = info; |
| } |
|
Primiano Tucci (use gerrit)
2017/03/31 19:05:47
minor thing, but this branch should return true,
|
| + |
| + return index_and_flag.second; |
| } |
| void AllocationRegister::Remove(const void* address) { |
| @@ -149,8 +152,10 @@ void AllocationRegister::EstimateTraceMemoryOverhead( |
| AllocationRegister::BacktraceMap::KVIndex AllocationRegister::InsertBacktrace( |
| const Backtrace& backtrace) { |
| auto index = backtraces_.Insert(backtrace, 0).first; |
| - auto& backtrace_and_count = backtraces_.Get(index); |
| - backtrace_and_count.second++; |
| + if (index != BacktraceMap::kInvalidKVIndex) { |
| + auto& backtrace_and_count = backtraces_.Get(index); |
| + backtrace_and_count.second++; |
| + } |
| return index; |
| } |