[lsan] Invoke leak detection with atexit().

Keeps it consistent between ASan and LSan.

llvm-svn: 182399
This commit is contained in:
Sergey Matveev 2013-05-21 17:56:45 +00:00
parent 3189891857
commit 20ccf95f80
4 changed files with 12 additions and 15 deletions

View File

@ -465,12 +465,6 @@ void __asan_init() {
Atexit(asan_atexit);
}
#if CAN_SANITIZE_LEAKS
if (flags()->detect_leaks) {
Atexit(__lsan::DoLeakCheck);
}
#endif
// interceptors
InitializeAsanInterceptors();
@ -550,12 +544,15 @@ void __asan_init() {
main_thread->ThreadStart(internal_getpid());
force_interface_symbols(); // no-op.
InitializeAllocator();
#if CAN_SANITIZE_LEAKS
__lsan::InitCommonLsan();
if (flags()->detect_leaks) {
Atexit(__lsan::DoLeakCheck);
}
#endif
InitializeAllocator();
if (flags()->verbosity) {
Report("AddressSanitizer Init done\n");
}

View File

@ -56,6 +56,11 @@ void Init() {
external_symbolizer[0]) {
InitializeExternalSymbolizer(external_symbolizer);
}
#if CAN_SANITIZE_LEAKS
__lsan::InitCommonLsan();
Atexit(__lsan::DoLeakCheck);
#endif
}
} // namespace __lsan

View File

@ -180,6 +180,7 @@ void ForEachChunk(Callable const &callback) {
allocator.ForEachChunk(callback);
}
#if CAN_SANITIZE_LEAKS
template void ForEachChunk<ProcessPlatformSpecificAllocationsCb>(
ProcessPlatformSpecificAllocationsCb const &callback);
template void ForEachChunk<PrintLeakedCb>(PrintLeakedCb const &callback);
@ -188,5 +189,5 @@ template void ForEachChunk<MarkIndirectlyLeakedCb>(
MarkIndirectlyLeakedCb const &callback);
template void ForEachChunk<ReportLeakedCb>(ReportLeakedCb const &callback);
template void ForEachChunk<ClearTagCb>(ClearTagCb const &callback);
#endif
} // namespace __lsan

View File

@ -17,15 +17,9 @@ clang++ ../sanitizer_common/sanitizer_*.cc ../interception/interception_*.cc \
-o lsan.so
LD_PRELOAD=./lsan.so /your/app
*/
#include "lsan_common.h"
#include "lsan.h"
__attribute__((constructor))
void constructor() {
__lsan::Init();
}
__attribute__((destructor))
void destructor() {
__lsan::DoLeakCheck();
}