| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_DEBUG_LEAK_ANNOTATIONS_H_ | 5 #ifndef BASE_DEBUG_LEAK_ANNOTATIONS_H_ |
| 6 #define BASE_DEBUG_LEAK_ANNOTATIONS_H_ | 6 #define BASE_DEBUG_LEAK_ANNOTATIONS_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 | 10 |
| 11 // This file defines macros which can be used to annotate intentional memory | 11 // This file defines macros which can be used to annotate intentional memory |
| 12 // leaks. Support for annotations is implemented in HeapChecker and | 12 // leaks. Support for annotations is implemented in LeakSanitizer. Annotated |
| 13 // LeakSanitizer. Annotated objects will be treated as a source of live | 13 // objects will be treated as a source of live pointers, i.e. any heap objects |
| 14 // pointers, i.e. any heap objects reachable by following pointers from an | 14 // reachable by following pointers from an annotated object will not be |
| 15 // annotated object will not be reported as leaks. | 15 // reported as leaks. |
| 16 // | 16 // |
| 17 // ANNOTATE_SCOPED_MEMORY_LEAK: all allocations made in the current scope | 17 // ANNOTATE_SCOPED_MEMORY_LEAK: all allocations made in the current scope |
| 18 // will be annotated as leaks. | 18 // will be annotated as leaks. |
| 19 // ANNOTATE_LEAKING_OBJECT_PTR(X): the heap object referenced by pointer X will | 19 // ANNOTATE_LEAKING_OBJECT_PTR(X): the heap object referenced by pointer X will |
| 20 // be annotated as a leak. | 20 // be annotated as a leak. |
| 21 // | |
| 22 // Note that HeapChecker will report a fatal error if an object which has been | |
| 23 // annotated with ANNOTATE_LEAKING_OBJECT_PTR is later deleted (but | |
| 24 // LeakSanitizer won't). | |
| 25 | 21 |
| 26 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL) && \ | 22 #if defined(LEAK_SANITIZER) && !defined(OS_NACL) |
| 27 defined(USE_HEAPCHECKER) | |
| 28 | |
| 29 #include "third_party/tcmalloc/chromium/src/gperftools/heap-checker.h" | |
| 30 | |
| 31 #define ANNOTATE_SCOPED_MEMORY_LEAK \ | |
| 32 HeapLeakChecker::Disabler heap_leak_checker_disabler; static_cast<void>(0) | |
| 33 | |
| 34 #define ANNOTATE_LEAKING_OBJECT_PTR(X) \ | |
| 35 HeapLeakChecker::IgnoreObject(X) | |
| 36 | |
| 37 #elif defined(LEAK_SANITIZER) && !defined(OS_NACL) | |
| 38 | 23 |
| 39 // Public LSan API from <sanitizer/lsan_interface.h>. | 24 // Public LSan API from <sanitizer/lsan_interface.h>. |
| 40 extern "C" { | 25 extern "C" { |
| 41 void __lsan_disable(); | 26 void __lsan_disable(); |
| 42 void __lsan_enable(); | 27 void __lsan_enable(); |
| 43 void __lsan_ignore_object(const void *p); | 28 void __lsan_ignore_object(const void *p); |
| 44 | 29 |
| 45 // Invoke leak detection immediately. If leaks are found, the process will exit. | 30 // Invoke leak detection immediately. If leaks are found, the process will exit. |
| 46 void __lsan_do_leak_check(); | 31 void __lsan_do_leak_check(); |
| 47 } // extern "C" | 32 } // extern "C" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 | 46 |
| 62 #else | 47 #else |
| 63 | 48 |
| 64 // If neither HeapChecker nor LSan are used, the annotations should be no-ops. | 49 // If neither HeapChecker nor LSan are used, the annotations should be no-ops. |
| 65 #define ANNOTATE_SCOPED_MEMORY_LEAK ((void)0) | 50 #define ANNOTATE_SCOPED_MEMORY_LEAK ((void)0) |
| 66 #define ANNOTATE_LEAKING_OBJECT_PTR(X) ((void)0) | 51 #define ANNOTATE_LEAKING_OBJECT_PTR(X) ((void)0) |
| 67 | 52 |
| 68 #endif | 53 #endif |
| 69 | 54 |
| 70 #endif // BASE_DEBUG_LEAK_ANNOTATIONS_H_ | 55 #endif // BASE_DEBUG_LEAK_ANNOTATIONS_H_ |
| OLD | NEW |