| 6 | #define BASE_DEBUG_LEAK_ANNOTATIONS_H_ |
| 7 |
| 8 | #include "base/macros.h" |
| 9 | #include "build/build_config.h" |
| 10 |
| 11 | // This file defines macros which can be used to annotate intentional memory |
| 12 | // leaks. Support for annotations is implemented in LeakSanitizer. Annotated |
| 13 | // objects will be treated as a source of live pointers, i.e. any heap objects |
| 14 | // reachable by following pointers from an annotated object will not be |
| 15 | // reported as leaks. |
| 16 | // |
| 17 | // ANNOTATE_SCOPED_MEMORY_LEAK: all allocations made in the current scope |
| 18 | // will be annotated as leaks. |
| 19 | // ANNOTATE_LEAKING_OBJECT_PTR(X): the heap object referenced by pointer X will |
| 20 | // be annotated as a leak. |
| 21 |
| 22 | #if defined(LEAK_SANITIZER) && !defined(OS_NACL) |
| 23 |
| 24 | #include <sanitizer/lsan_interface.h> |
| 25 |
| 26 | class ScopedLeakSanitizerDisabler { |
| 27 | public: |
| 28 | ScopedLeakSanitizerDisabler() { __lsan_disable(); } |
| 29 | ~ScopedLeakSanitizerDisabler() { __lsan_enable(); } |
| 30 | private: |
| 31 | DISALLOW_COPY_AND_ASSIGN(ScopedLeakSanitizerDisabler); |
| 32 | }; |
| 33 |
| 34 | #define ANNOTATE_SCOPED_MEMORY_LEAK \ |
| 35 | ScopedLeakSanitizerDisabler leak_sanitizer_disabler; static_cast<void>(0) |
| 36 |
| 37 | #define ANNOTATE_LEAKING_OBJECT_PTR(X) __lsan_ignore_object(X); |
| 38 |
| 39 | #else |
| 40 |
| 41 | #define ANNOTATE_SCOPED_MEMORY_LEAK ((void)0) |
| 42 | #define ANNOTATE_LEAKING_OBJECT_PTR(X) ((void)0) |
| 43 |
| 44 | #endif |
| 45 |
| 46 | #endif // BASE_DEBUG_LEAK_ANNOTATIONS_H_ |
| 47 |