summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/lib/asan/asan_flags.h2
-rw-r--r--compiler-rt/lib/asan/asan_rtl.cc13
-rw-r--r--compiler-rt/lib/lsan/lsan.cc1
-rw-r--r--compiler-rt/lib/lsan/lsan_common.cc5
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_flags.cc1
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_flags.h2
6 files changed, 13 insertions, 11 deletions
diff --git a/compiler-rt/lib/asan/asan_flags.h b/compiler-rt/lib/asan/asan_flags.h
index d0f821a85c4..b83a1473122 100644
--- a/compiler-rt/lib/asan/asan_flags.h
+++ b/compiler-rt/lib/asan/asan_flags.h
@@ -106,8 +106,6 @@ struct Flags {
// If true, assume that dynamic initializers can never access globals from
// other modules, even if the latter are already initialized.
bool strict_init_order;
- // Invoke LeakSanitizer at process exit.
- bool detect_leaks;
};
extern Flags asan_flags_dont_use_directly;
diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc
index 19ed2b795dd..1315c2f6f6e 100644
--- a/compiler-rt/lib/asan/asan_rtl.cc
+++ b/compiler-rt/lib/asan/asan_rtl.cc
@@ -124,7 +124,6 @@ static void ParseFlagsFromString(Flags *f, const char *str) {
ParseFlag(str, &f->use_stack_depot, "use_stack_depot");
ParseFlag(str, &f->strict_memcmp, "strict_memcmp");
ParseFlag(str, &f->strict_init_order, "strict_init_order");
- ParseFlag(str, &f->detect_leaks, "detect_leaks");
}
void InitializeFlags(Flags *f, const char *env) {
@@ -137,6 +136,7 @@ void InitializeFlags(Flags *f, const char *env) {
cf->strip_path_prefix = "";
cf->handle_ioctl = false;
cf->log_path = 0;
+ cf->detect_leaks = false;
internal_memset(f, 0, sizeof(*f));
f->quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 26 : 1UL << 28;
@@ -173,7 +173,6 @@ void InitializeFlags(Flags *f, const char *env) {
f->use_stack_depot = true;
f->strict_memcmp = true;
f->strict_init_order = false;
- f->detect_leaks = false;
// Override from compile definition.
ParseFlagsFromString(f, MaybeUseAsanDefaultOptionsCompileDefiniton());
@@ -189,17 +188,17 @@ void InitializeFlags(Flags *f, const char *env) {
ParseFlagsFromString(f, env);
#if !CAN_SANITIZE_LEAKS
- if (f->detect_leaks) {
+ if (cf->detect_leaks) {
Report("%s: detect_leaks is not supported on this platform.\n",
SanitizerToolName);
- f->detect_leaks = false;
+ cf->detect_leaks = false;
}
#endif
- if (f->detect_leaks && !f->use_stack_depot) {
+ if (cf->detect_leaks && !f->use_stack_depot) {
Report("%s: detect_leaks is ignored (requires use_stack_depot).\n",
SanitizerToolName);
- f->detect_leaks = false;
+ cf->detect_leaks = false;
}
}
@@ -557,7 +556,7 @@ void __asan_init() {
#if CAN_SANITIZE_LEAKS
__lsan::InitCommonLsan();
- if (flags()->detect_leaks) {
+ if (common_flags()->detect_leaks) {
Atexit(__lsan::DoLeakCheck);
}
#endif // CAN_SANITIZE_LEAKS
diff --git a/compiler-rt/lib/lsan/lsan.cc b/compiler-rt/lib/lsan/lsan.cc
index c917bcc750f..79e593f8b57 100644
--- a/compiler-rt/lib/lsan/lsan.cc
+++ b/compiler-rt/lib/lsan/lsan.cc
@@ -30,6 +30,7 @@ static void InitializeCommonFlags() {
cf->strip_path_prefix = "";
cf->fast_unwind_on_malloc = true;
cf->malloc_context_size = 30;
+ cf->detect_leaks = true;
ParseCommonFlagsFromString(GetEnv("LSAN_OPTIONS"));
}
diff --git a/compiler-rt/lib/lsan/lsan_common.cc b/compiler-rt/lib/lsan/lsan_common.cc
index 8f57ae00520..265b1ce333e 100644
--- a/compiler-rt/lib/lsan/lsan_common.cc
+++ b/compiler-rt/lib/lsan/lsan_common.cc
@@ -550,8 +550,9 @@ void __lsan_enable() {
SANITIZER_INTERFACE_ATTRIBUTE
void __lsan_do_leak_check() {
#if CAN_SANITIZE_LEAKS
- __lsan::DoLeakCheck();
-#endif
+ if (common_flags()->detect_leaks)
+ __lsan::DoLeakCheck();
+#endif // CAN_SANITIZE_LEAKS
}
#if !SANITIZER_SUPPORTS_WEAK_HOOKS
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc
index b8b1c3b66ca..ed7336a75ee 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc
@@ -29,6 +29,7 @@ void ParseCommonFlagsFromString(const char *str) {
ParseFlag(str, &f->symbolize, "symbolize");
ParseFlag(str, &f->handle_ioctl, "handle_ioctl");
ParseFlag(str, &f->log_path, "log_path");
+ ParseFlag(str, &f->detect_leaks, "detect_leaks");
}
static bool GetFlagValue(const char *env, const char *name,
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.h b/compiler-rt/lib/sanitizer_common/sanitizer_flags.h
index 16cbc645cc3..f3f4a26f05e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.h
@@ -39,6 +39,8 @@ struct CommonFlags {
int malloc_context_size;
// Write logs to "log_path.pid" instead of stderr.
const char *log_path;
+ // Enable memory leak detection.
+ bool detect_leaks;
};
extern CommonFlags common_flags_dont_use_directly;
OpenPOWER on IntegriCloud