Skip to content

Commit 1b58389

Browse files
committed
Add __lsan::ScopedInterceptorDisabler for strerror(3)
Summary: strerror(3) on NetBSD uses internally TSD with a destructor that is never fired for exit(3). It's correctly called for pthread_exit(3) scenarios. This is a case when a leak on exit(3) is expected, unavoidable and harmless. Reviewers: joerg, vitalybuka, dvyukov, mgorny Reviewed By: vitalybuka Subscribers: dmgreen, kristof.beyls, jfb, llvm-commits, #sanitizers Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D67337 llvm-svn: 372461
1 parent 5fe1e55 commit 1b58389

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

compiler-rt/lib/asan/asan_interceptors.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
164164
ASAN_MEMSET_IMPL(ctx, block, c, size); \
165165
} while (false)
166166

167+
#if CAN_SANITIZE_LEAKS
168+
#define COMMON_INTERCEPTOR_STRERROR() \
169+
__lsan::ScopedInterceptorDisabler disabler
170+
#endif
171+
167172
#include "sanitizer_common/sanitizer_common_interceptors.inc"
168173
#include "sanitizer_common/sanitizer_signal_interceptors.inc"
169174

compiler-rt/lib/lsan/lsan_interceptors.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,16 @@ INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(),
383383
#define LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK
384384
#endif
385385

386+
#if SANITIZER_INTERCEPT_STRERROR
387+
INTERCEPTOR(char *, strerror, int errnum) {
388+
__lsan::ScopedInterceptorDisabler disabler;
389+
return REAL(strerror)(errnum);
390+
}
391+
#define LSAN_MAYBE_INTERCEPT_STRERROR INTERCEPT_FUNCTION(strerror)
392+
#else
393+
#define LSAN_MAYBE_INTERCEPT_STRERROR
394+
#endif
395+
386396
struct ThreadParam {
387397
void *(*callback)(void *arg);
388398
void *param;
@@ -496,6 +506,8 @@ void InitializeInterceptors() {
496506
LSAN_MAYBE_INTERCEPT_ATEXIT;
497507
LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK;
498508

509+
LSAN_MAYBE_INTERCEPT_STRERROR;
510+
499511
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
500512
if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) {
501513
Report("LeakSanitizer: failed to create thread key.\n");

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
// COMMON_INTERCEPTOR_MMAP_IMPL
3737
// COMMON_INTERCEPTOR_COPY_STRING
3838
// COMMON_INTERCEPTOR_STRNDUP_IMPL
39+
// COMMON_INTERCEPTOR_STRERROR
3940
//===----------------------------------------------------------------------===//
4041

4142
#include "interception/interception.h"
@@ -301,6 +302,10 @@ bool PlatformHasDifferentMemcpyAndMemmove();
301302
return new_mem;
302303
#endif
303304

305+
#ifndef COMMON_INTERCEPTOR_STRERROR
306+
#define COMMON_INTERCEPTOR_STRERROR() {}
307+
#endif
308+
304309
struct FileMetadata {
305310
// For open_memstream().
306311
char **addr;
@@ -3677,6 +3682,7 @@ INTERCEPTOR(int, sched_getparam, int pid, void *param) {
36773682
INTERCEPTOR(char *, strerror, int errnum) {
36783683
void *ctx;
36793684
COMMON_INTERCEPTOR_ENTER(ctx, strerror, errnum);
3685+
COMMON_INTERCEPTOR_STRERROR();
36803686
char *res = REAL(strerror)(errnum);
36813687
if (res) COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, REAL(strlen)(res) + 1);
36823688
return res;

0 commit comments

Comments
 (0)