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

Side by Side Diff: components/metrics/leak_detector/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: Mac build fixes: const arg in comparator, rm const in func return type Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/metrics/leak_detector/custom_allocator.h"
6
7 #include <stddef.h>
8
9 namespace metrics {
10 namespace leak_detector {
11
12 namespace {
13
14 // Wrappers around new and delete.
15 void* DefaultAlloc(size_t size) {
16 return new char[size];
17 }
18 void DefaultFree(void* ptr, size_t /* size */) {
19 delete[] reinterpret_cast<char*>(ptr);
20 }
21
22 CustomAllocator::AllocFunc g_alloc_func = nullptr;
23 CustomAllocator::FreeFunc g_free_func = nullptr;
24
25 } // namespace
26
27 // static
28 void CustomAllocator::Initialize() {
29 Initialize(&DefaultAlloc, &DefaultFree);
30 }
31
32 // static
33 void CustomAllocator::Initialize(AllocFunc alloc_func, FreeFunc free_func) {
34 g_alloc_func = alloc_func;
35 g_free_func = free_func;
36 }
37
38 // static
39 bool CustomAllocator::Shutdown() {
40 g_alloc_func = nullptr;
41 g_free_func = nullptr;
42 return true;
43 }
44
45 // static
46 bool CustomAllocator::IsInitialized() {
47 return g_alloc_func && g_free_func;
48 }
49
50 // static
51 void* CustomAllocator::Allocate(size_t size) {
52 return g_alloc_func(size);
53 }
54
55 // static
56 void CustomAllocator::Free(void* ptr, size_t size) {
57 g_free_func(ptr, size);
58 }
59
60 } // namespace leak_detector
61 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/leak_detector/custom_allocator.h ('k') | components/metrics/leak_detector/leak_analyzer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698