@@ -706,6 +706,9 @@ static void AtCxaAtexit(void *unused) {
706706#endif
707707
708708#if ASAN_INTERCEPT___CXA_ATEXIT
709+ #ifdef SANITIZER_NETBSD
710+ DECLARE_REAL (int , atexit, void (*func)());
711+ #endif
709712INTERCEPTOR (int , __cxa_atexit, void (*func)(void *), void *arg,
710713 void *dso_handle) {
711714#if SANITIZER_APPLE
@@ -717,7 +720,11 @@ INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
717720 __lsan::ScopedInterceptorDisabler disabler;
718721#endif
719722 int res = REAL (__cxa_atexit)(func, arg, dso_handle);
723+ #ifdef SANITIZER_NETBSD
724+ REAL (atexit)((void (*)())AtCxaAtexit);
725+ #else
720726 REAL (__cxa_atexit)(AtCxaAtexit, nullptr , nullptr );
727+ #endif
721728 return res;
722729}
723730#endif // ASAN_INTERCEPT___CXA_ATEXIT
@@ -728,9 +735,14 @@ INTERCEPTOR(int, atexit, void (*func)()) {
728735#if CAN_SANITIZE_LEAKS
729736 __lsan::ScopedInterceptorDisabler disabler;
730737#endif
738+ #ifdef SANITIZER_NETBSD
739+ int res = REAL (atexit)(func);
740+ REAL (atexit)((void (*)())AtCxaAtexit);
741+ #else
731742 // Avoid calling real atexit as it is unreachable on at least on Linux.
732743 int res = REAL (__cxa_atexit)((void (*)(void *a))func, nullptr , nullptr );
733744 REAL (__cxa_atexit)(AtCxaAtexit, nullptr , nullptr );
745+ #endif
734746 return res;
735747}
736748#endif
0 commit comments