Skip to content

Commit 79aa81e

Browse files
committed
Only call __lsan_do_leak_check() for pthread builds
Non-pthreads builds can safely use atexit().
1 parent af4626c commit 79aa81e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ def check_memory_setting(setting):
21432143
if settings.LINKABLE:
21442144
exit_with_error('ASan does not support dynamic linking')
21452145

2146-
if sanitize and settings.EXIT_RUNTIME:
2146+
if sanitize and settings.USE_PTHREADS and settings.EXIT_RUNTIME:
21472147
settings.EXPORTED_FUNCTIONS += ['___lsan_do_leak_check']
21482148

21492149
if sanitize and settings.GENERATE_SOURCE_MAP:

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,10 @@ function exitRuntime() {
435435
#endif
436436
#if USE_PTHREADS
437437
PThread.terminateAllThreads();
438-
#endif
439438
#if EXIT_RUNTIME && (USE_LSAN || USE_ASAN)
440439
// Leak check should be run after all threads have been terminated.
441440
___lsan_do_leak_check();
441+
#endif
442442
#endif
443443
runtimeExited = true;
444444
}

system/lib/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ COMMON_FLAG(bool, strip_env, 1,
7171
"avoid passing it to children. Default is true.")
7272
COMMON_FLAG(bool, detect_leaks, !SANITIZER_MAC, "Enable memory leak detection.")
7373
COMMON_FLAG(
74-
bool, leak_check_at_exit, !SANITIZER_EMSCRIPTEN,
74+
bool, leak_check_at_exit,
75+
#ifdef __EMSCRIPTEN_PTHREADS__
76+
false,
77+
#else
78+
true,
79+
#endif
7580
"Invoke leak checking in an atexit handler. Has no effect if "
7681
"detect_leaks=false, or if __lsan_do_leak_check() is called before the "
7782
"handler has a chance to run.")

0 commit comments

Comments
 (0)