[lsan] Invoke leak detection with atexit().

Keeps it consistent between ASan and LSan.

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182399 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/lsan/lsan.cc b/lib/lsan/lsan.cc
index 84466a1..278492b 100644
--- a/lib/lsan/lsan.cc
+++ b/lib/lsan/lsan.cc
@@ -56,6 +56,11 @@
       external_symbolizer[0]) {
     InitializeExternalSymbolizer(external_symbolizer);
   }
+
+#if CAN_SANITIZE_LEAKS
+  __lsan::InitCommonLsan();
+    Atexit(__lsan::DoLeakCheck);
+#endif
 }
 
 }  // namespace __lsan
diff --git a/lib/lsan/lsan_allocator.cc b/lib/lsan/lsan_allocator.cc
index b131d38..cde18c9 100644
--- a/lib/lsan/lsan_allocator.cc
+++ b/lib/lsan/lsan_allocator.cc
@@ -180,6 +180,7 @@
   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 @@
     MarkIndirectlyLeakedCb const &callback);
 template void ForEachChunk<ReportLeakedCb>(ReportLeakedCb const &callback);
 template void ForEachChunk<ClearTagCb>(ClearTagCb const &callback);
-
+#endif
 }  // namespace __lsan
diff --git a/lib/lsan/tests/lsan_testlib.cc b/lib/lsan/tests/lsan_testlib.cc
index 142f187..363cc14 100644
--- a/lib/lsan/tests/lsan_testlib.cc
+++ b/lib/lsan/tests/lsan_testlib.cc
@@ -17,15 +17,9 @@
  -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();
-}