Add __lsan::ScopedInterceptorDisabler for strerror(3)
Cherry-pick and adapt: commit 1b58389428ed07a7322ba9c2bcaeec99807f9457 Author: Kamil Rytarowski <n54@gmx.com> Date: Sat Sep 21 07:45:02 2019 +0000 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
This commit is contained in:
parent
a476aad3c2
commit
31e31781c6
@ -163,6 +163,11 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
|
||||
ASAN_MEMSET_IMPL(ctx, block, c, size); \
|
||||
} while (false)
|
||||
|
||||
#if CAN_SANITIZE_LEAKS
|
||||
#define COMMON_INTERCEPTOR_STRERROR() \
|
||||
__lsan::ScopedInterceptorDisabler disabler
|
||||
#endif
|
||||
|
||||
#include "sanitizer_common/sanitizer_common_interceptors.inc"
|
||||
#include "sanitizer_common/sanitizer_signal_interceptors.inc"
|
||||
|
||||
|
@ -338,6 +338,16 @@ INTERCEPTOR(void, thr_exit, tid_t *state) {
|
||||
#define LSAN_MAYBE_INTERCEPT_THR_EXIT
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_STRERROR
|
||||
INTERCEPTOR(char *, strerror, int errnum) {
|
||||
__lsan::ScopedInterceptorDisabler disabler;
|
||||
return REAL(strerror)(errnum);
|
||||
}
|
||||
#define LSAN_MAYBE_INTERCEPT_STRERROR INTERCEPT_FUNCTION(strerror)
|
||||
#else
|
||||
#define LSAN_MAYBE_INTERCEPT_STRERROR
|
||||
#endif
|
||||
|
||||
struct ThreadParam {
|
||||
void *(*callback)(void *arg);
|
||||
void *param;
|
||||
@ -447,6 +457,8 @@ void InitializeInterceptors() {
|
||||
LSAN_MAYBE_INTERCEPT__LWP_EXIT;
|
||||
LSAN_MAYBE_INTERCEPT_THR_EXIT;
|
||||
|
||||
LSAN_MAYBE_INTERCEPT_STRERROR;
|
||||
|
||||
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
|
||||
if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) {
|
||||
Report("LeakSanitizer: failed to create thread key.\n");
|
||||
|
@ -35,6 +35,7 @@
|
||||
// COMMON_INTERCEPTOR_MMAP_IMPL
|
||||
// COMMON_INTERCEPTOR_COPY_STRING
|
||||
// COMMON_INTERCEPTOR_STRNDUP_IMPL
|
||||
// COMMON_INTERCEPTOR_STRERROR
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "interception/interception.h"
|
||||
@ -290,6 +291,10 @@ bool PlatformHasDifferentMemcpyAndMemmove();
|
||||
return new_mem;
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_INTERCEPTOR_STRERROR
|
||||
#define COMMON_INTERCEPTOR_STRERROR() {}
|
||||
#endif
|
||||
|
||||
struct FileMetadata {
|
||||
// For open_memstream().
|
||||
char **addr;
|
||||
@ -3631,6 +3636,7 @@ INTERCEPTOR(int, sched_getparam, int pid, void *param) {
|
||||
INTERCEPTOR(char *, strerror, int errnum) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, strerror, errnum);
|
||||
COMMON_INTERCEPTOR_STRERROR();
|
||||
char *res = REAL(strerror)(errnum);
|
||||
if (res) COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, REAL(strlen)(res) + 1);
|
||||
return res;
|
||||
|
Loading…
Reference in New Issue
Block a user