22
22
#include " sanitizer_common/sanitizer_internal_defs.h"
23
23
#include " sanitizer_common/sanitizer_libc.h"
24
24
#include " sanitizer_common/sanitizer_linux.h"
25
+ #include " sanitizer_common/sanitizer_platform_interceptors.h"
25
26
#include " sanitizer_common/sanitizer_platform_limits_netbsd.h"
26
27
#include " sanitizer_common/sanitizer_platform_limits_posix.h"
27
28
#include " sanitizer_common/sanitizer_posix.h"
@@ -747,6 +748,41 @@ TSAN_INTERCEPTOR(void, free, void *p) {
747
748
user_free (thr, pc, p);
748
749
}
749
750
751
+ # if SANITIZER_INTERCEPT_FREE_SIZED
752
+ TSAN_INTERCEPTOR (void , free_sized, void *p, uptr size) {
753
+ if (UNLIKELY (!p))
754
+ return ;
755
+ if (in_symbolizer ())
756
+ return InternalFree (p);
757
+ if (DlsymAlloc::PointerIsMine (p))
758
+ return DlsymAlloc::Free (p);
759
+ invoke_free_hook (p);
760
+ SCOPED_INTERCEPTOR_RAW (free_sized, p, size);
761
+ user_free (thr, pc, p);
762
+ }
763
+ # define TSAN_MAYBE_INTERCEPT_FREE_SIZED INTERCEPT_FUNCTION (free_sized)
764
+ # else
765
+ # define TSAN_MAYBE_INTERCEPT_FREE_SIZED
766
+ # endif
767
+
768
+ # if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED
769
+ TSAN_INTERCEPTOR (void , free_aligned_sized, void *p, uptr alignment, uptr size) {
770
+ if (UNLIKELY (!p))
771
+ return ;
772
+ if (in_symbolizer ())
773
+ return InternalFree (p);
774
+ if (DlsymAlloc::PointerIsMine (p))
775
+ return DlsymAlloc::Free (p);
776
+ invoke_free_hook (p);
777
+ SCOPED_INTERCEPTOR_RAW (free_aligned_sized, p, alignment, size);
778
+ user_free (thr, pc, p);
779
+ }
780
+ # define TSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED \
781
+ INTERCEPT_FUNCTION (free_aligned_sized)
782
+ # else
783
+ # define TSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED
784
+ # endif
785
+
750
786
TSAN_INTERCEPTOR (void , cfree, void *p) {
751
787
if (UNLIKELY (!p))
752
788
return ;
@@ -763,6 +799,9 @@ TSAN_INTERCEPTOR(uptr, malloc_usable_size, void *p) {
763
799
SCOPED_INTERCEPTOR_RAW (malloc_usable_size, p);
764
800
return user_alloc_usable_size (p);
765
801
}
802
+ #else
803
+ # define TSAN_MAYBE_INTERCEPT_FREE_SIZED
804
+ # define TSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED
766
805
#endif
767
806
768
807
TSAN_INTERCEPTOR (char *, strcpy, char *dst, const char *src) {
@@ -2963,6 +3002,8 @@ void InitializeInterceptors() {
2963
3002
TSAN_INTERCEPT (realloc);
2964
3003
TSAN_INTERCEPT (reallocarray);
2965
3004
TSAN_INTERCEPT (free);
3005
+ TSAN_MAYBE_INTERCEPT_FREE_SIZED;
3006
+ TSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED;
2966
3007
TSAN_INTERCEPT (cfree);
2967
3008
TSAN_INTERCEPT (munmap);
2968
3009
TSAN_MAYBE_INTERCEPT_MEMALIGN;
0 commit comments