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 "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL) && \ | 10 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL) && \ |
11 defined(USE_HEAPCHECKER) | 11 defined(USE_HEAPCHECKER) |
12 | 12 |
13 #include "third_party/tcmalloc/chromium/src/gperftools/heap-checker.h" | 13 #include "third_party/tcmalloc/chromium/src/gperftools/heap-checker.h" |
14 | 14 |
15 // Annotate a program scope as having memory leaks. Tcmalloc's heap leak | 15 // Annotate a program scope as having memory leaks. Tcmalloc's heap leak |
Alexander Potapenko
2013/06/13 10:47:56
Can you please move the descriptions of the annota
| |
16 // checker will ignore them. Note that these annotations may mask real bugs | 16 // checker will ignore them. Note that these annotations may mask real bugs |
17 // and should not be used in the production code. | 17 // and should not be used in the production code. |
18 #define ANNOTATE_SCOPED_MEMORY_LEAK \ | 18 #define ANNOTATE_SCOPED_MEMORY_LEAK \ |
19 HeapLeakChecker::Disabler heap_leak_checker_disabler | 19 HeapLeakChecker::Disabler heap_leak_checker_disabler |
20 | 20 |
21 // Annotate an object pointer as referencing a leaky object. This object and all | 21 // Annotate an object pointer as referencing a leaky object. This object and all |
22 // the heap objects referenced by it will be ignored by the heap checker. | 22 // the heap objects referenced by it will be ignored by the heap checker. |
23 // | 23 // |
24 // X should be referencing an active allocated object. If it is not, the | 24 // X should be referencing an active allocated object. If it is not, the |
25 // annotation will be ignored. | 25 // annotation will be ignored. |
26 // No object should be annotated with ANNOTATE_SCOPED_MEMORY_LEAK twice. | 26 // No object should be annotated with ANNOTATE_SCOPED_MEMORY_LEAK twice. |
27 // Once an object is annotated with ANNOTATE_SCOPED_MEMORY_LEAK, it cannot be | 27 // Once an object is annotated with ANNOTATE_SCOPED_MEMORY_LEAK, it cannot be |
28 // deleted. | 28 // deleted. |
29 #define ANNOTATE_LEAKING_OBJECT_PTR(X) \ | 29 #define ANNOTATE_LEAKING_OBJECT_PTR(X) \ |
30 HeapLeakChecker::IgnoreObject(X) | 30 HeapLeakChecker::IgnoreObject(X) |
31 | 31 |
32 #elif defined(LEAK_SANITIZER) | |
33 | |
34 // LeakSanitizer supports the same annotations as HeapChecker above. | |
35 // Beware that LeakSanitizer does not report a fatal error when an object is | |
36 // annotated twice, or an annotated object is deleted. This can be a source of | |
37 // discrepancy between LSan and HeapChecker builds. | |
38 | |
39 extern "C" { | |
40 void __lsan_disable(); | |
41 void __lsan_enable(); | |
42 void __lsan_ignore_object(const void *p); | |
43 } // extern "C" | |
44 | |
45 namespace __lsan { | |
46 class ScopedLeakSanitizerDisabler { | |
47 public: | |
48 ScopedLeakSanitizerDisabler() { __lsan_disable(); } | |
49 ~ScopedLeakSanitizerDisabler() { __lsan_enable(); } | |
50 private: | |
51 // Disallow copy and assign. | |
52 ScopedLeakSanitizerDisabler(const ScopedLeakSanitizerDisabler&); | |
jar (doing other things)
2013/06/12 18:43:59
explicit?
| |
53 void operator=(const ScopedLeakSanitizerDisabler&); | |
54 }; | |
55 } // namespace __lsan | |
56 | |
57 #define ANNOTATE_SCOPED_MEMORY_LEAK \ | |
58 __lsan::ScopedLeakSanitizerDisabler leak_sanitizer_disabler | |
59 | |
60 #define ANNOTATE_LEAKING_OBJECT_PTR(X) __lsan_ignore_object(X); | |
61 | |
32 #else | 62 #else |
33 | 63 |
34 // If tcmalloc is not used, the annotations should be no-ops. | 64 // If neither HeapChecker nor LSan are used, the annotations should be no-ops. |
35 #define ANNOTATE_SCOPED_MEMORY_LEAK ((void)0) | 65 #define ANNOTATE_SCOPED_MEMORY_LEAK ((void)0) |
36 #define ANNOTATE_LEAKING_OBJECT_PTR(X) ((void)0) | 66 #define ANNOTATE_LEAKING_OBJECT_PTR(X) ((void)0) |
37 | 67 |
38 #endif | 68 #endif |
39 | 69 |
40 #endif // BASE_DEBUG_LEAK_ANNOTATIONS_H_ | 70 #endif // BASE_DEBUG_LEAK_ANNOTATIONS_H_ |
OLD | NEW |