Index: third_party/tcmalloc/chromium/src/heap-profiler.cc |
diff --git a/third_party/tcmalloc/chromium/src/heap-profiler.cc b/third_party/tcmalloc/chromium/src/heap-profiler.cc |
index 85d1aadf7148b80f2a8b8d3c0096cf697dd5f81e..95827b2c79d35a02fef4a26a1ddade13c93bd0c6 100644 |
--- a/third_party/tcmalloc/chromium/src/heap-profiler.cc |
+++ b/third_party/tcmalloc/chromium/src/heap-profiler.cc |
@@ -152,6 +152,23 @@ static void ProfilerFree(void* p) { |
LowLevelAlloc::Free(p); |
} |
+static LowLevelAlloc::Arena *mmap_heap_profiler_memory = NULL; |
+ |
+static void* MMapProfilerMalloc(size_t bytes) { |
+ return LowLevelAlloc::AllocWithArena(bytes, mmap_heap_profiler_memory); |
+} |
+static void MMapProfilerFree(void* p) { |
+ LowLevelAlloc::Free(p); |
+} |
+ |
+static void DeleteMMapProfilerArenaIfExists() { |
+ if (mmap_heap_profiler_memory != NULL) { |
jar (doing other things)
2012/04/04 17:38:40
nit: Early return tends to improve readability (yo
Dai Mikurube (NOT FULLTIME)
2012/04/05 05:19:26
Done.
|
+ if (!LowLevelAlloc::DeleteArena(mmap_heap_profiler_memory)) |
+ RAW_LOG(FATAL, "Memory leak in HeapProfiler:"); |
+ mmap_heap_profiler_memory = NULL; |
+ } |
+} |
+ |
// We use buffers of this size in DoGetHeapProfile. |
// The size is 1 << 20 in the original google-perftools. Changed it to |
// 5 << 20 since a larger buffer is requried for deeper profiling in Chromium. |
@@ -200,7 +217,11 @@ static char* DoGetHeapProfileLocked(char* buf, int buflen) { |
int bytes_written = 0; |
if (is_on) { |
if (FLAGS_mmap_profile) { |
- heap_profile->RefreshMMapData(); |
+ if (mmap_heap_profiler_memory != NULL) |
+ DeleteMMapProfilerArenaIfExists(); |
+ mmap_heap_profiler_memory = |
+ LowLevelAlloc::NewArena(0, LowLevelAlloc::DefaultArena()); |
+ heap_profile->RefreshMMapData(MMapProfilerMalloc, MMapProfilerFree); |
} |
if (deep_profile) { |
bytes_written = deep_profile->FillOrderedProfile(buf, buflen - 1); |
@@ -208,7 +229,8 @@ static char* DoGetHeapProfileLocked(char* buf, int buflen) { |
bytes_written = heap_profile->FillOrderedProfile(buf, buflen - 1); |
} |
if (FLAGS_mmap_profile) { |
- heap_profile->ClearMMapData(); |
+ heap_profile->ClearMMapData(MMapProfilerFree); |
+ DeleteMMapProfilerArenaIfExists(); |
} |
} |
buf[bytes_written] = '\0'; |
@@ -532,6 +554,7 @@ extern "C" void HeapProfilerStop() { |
// free profile |
heap_profile->~HeapProfileTable(); |
+ DeleteMMapProfilerArenaIfExists(); |
ProfilerFree(heap_profile); |
heap_profile = NULL; |