[llvm-branch-commits] [sanitizer] Clear pending dlerror on thread exit before unregistering (PR #228930)

Vitaly Buka via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Oct 4 11:35:41 PDT 2026


https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/228930

Starting with glibc 2.34, failed dlfcn calls store a per-thread error
struct in TLS (__libc_dlerror_result) instead of a pthread_key_t, and
free it in __libc_thread_freeres() after all pthread TSD destructors
have completed.

Because ASan, LSan, and HWASan unregister the exiting thread in their
pthread TSD destructors during __nptl_deallocate_tsd(), LSan stops
scanning that thread's TLS before __libc_thread_freeres() frees
__libc_dlerror_result. If a leak check runs in that window (for example,
when the main thread exits while a detached worker thread is finishing)
and libc debug symbols are not installed to match the default *dlerror*
suppression on _dlerror_run, LSan reports a false positive leak from
dlsym/dlopen.

Call `if (dlerror()) dlerror();` before unregistering the exiting thread
so glibc frees its per-thread dlerror buffer while the thread is still
tracked.

Assisted-by: Gemini





More information about the llvm-branch-commits mailing list