Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Unified Diff: third_party/tcmalloc/chromium/src/custom_allocator.cc

Issue 986503002: components/metrics: Add runtime memory leak detector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix style, comments, RAW_CHECK in stl_allocator.h Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/custom_allocator.cc
diff --git a/third_party/tcmalloc/chromium/src/custom_allocator.cc b/third_party/tcmalloc/chromium/src/custom_allocator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4f13ee045f631a37437f4886f739d154a9e164cd
--- /dev/null
+++ b/third_party/tcmalloc/chromium/src/custom_allocator.cc
@@ -0,0 +1,37 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <gperftools/custom_allocator.h>
+
+#include "base/low_level_alloc.h"
+
+static LowLevelAlloc::Arena* g_arena = nullptr;
+
+// static
+void CustomAllocator::Initialize() {
+ g_arena = LowLevelAlloc::NewArena(0, LowLevelAlloc::DefaultArena());
+}
+
+// static
+bool CustomAllocator::Shutdown() {
+ return LowLevelAlloc::DeleteArena(g_arena);
+}
+
+// static
+bool CustomAllocator::IsInitialized() {
+ return g_arena;
+}
+
+// static
+void* CustomAllocator::Allocate(size_t size) {
+ if (!g_arena)
+ return nullptr;
+
+ return LowLevelAlloc::AllocWithArena(size, g_arena);
+}
+
+// static
+void CustomAllocator::Free(void* ptr, size_t /* size */) {
+ LowLevelAlloc::Free(ptr);
+}

Powered by Google App Engine
This is Rietveld 408576698