|
34 | 34 | #include "sanitizer_common/sanitizer_glibc_version.h"
|
35 | 35 | #include "sanitizer_common/sanitizer_libc.h"
|
36 | 36 | #include "sanitizer_common/sanitizer_linux.h"
|
| 37 | +#include "sanitizer_common/sanitizer_platform_interceptors.h" |
37 | 38 | #include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
|
38 | 39 | #include "sanitizer_common/sanitizer_platform_limits_posix.h"
|
39 | 40 | #include "sanitizer_common/sanitizer_stackdepot.h"
|
@@ -215,6 +216,35 @@ INTERCEPTOR(void, free, void *ptr) {
|
215 | 216 | MsanDeallocate(&stack, ptr);
|
216 | 217 | }
|
217 | 218 |
|
| 219 | +#if SANITIZER_INTERCEPT_FREE_SIZED |
| 220 | +INTERCEPTOR(void, free_sized, void *ptr, uptr size) { |
| 221 | + if (UNLIKELY(!ptr)) |
| 222 | + return; |
| 223 | + if (DlsymAlloc::PointerIsMine(ptr)) |
| 224 | + return DlsymAlloc::Free(ptr); |
| 225 | + GET_MALLOC_STACK_TRACE; |
| 226 | + MsanDeallocate(&stack, ptr); |
| 227 | +} |
| 228 | +# define MSAN_MAYBE_INTERCEPT_FREE_SIZED INTERCEPT_FUNCTION(free_sized) |
| 229 | +#else |
| 230 | +# define MSAN_MAYBE_INTERCEPT_FREE_SIZED |
| 231 | +#endif |
| 232 | + |
| 233 | +#if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED |
| 234 | +INTERCEPTOR(void, free_aligned_sized, void *ptr, uptr alignment, uptr size) { |
| 235 | + if (UNLIKELY(!ptr)) |
| 236 | + return; |
| 237 | + if (DlsymAlloc::PointerIsMine(ptr)) |
| 238 | + return DlsymAlloc::Free(ptr); |
| 239 | + GET_MALLOC_STACK_TRACE; |
| 240 | + MsanDeallocate(&stack, ptr); |
| 241 | +} |
| 242 | +# define MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED \ |
| 243 | + INTERCEPT_FUNCTION(free_aligned_sized) |
| 244 | +#else |
| 245 | +# define MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED |
| 246 | +#endif |
| 247 | + |
218 | 248 | #if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
|
219 | 249 | INTERCEPTOR(void, cfree, void *ptr) {
|
220 | 250 | if (UNLIKELY(!ptr))
|
@@ -1775,6 +1805,8 @@ void InitializeInterceptors() {
|
1775 | 1805 | INTERCEPT_FUNCTION(realloc);
|
1776 | 1806 | INTERCEPT_FUNCTION(reallocarray);
|
1777 | 1807 | INTERCEPT_FUNCTION(free);
|
| 1808 | + MSAN_MAYBE_INTERCEPT_FREE_SIZED; |
| 1809 | + MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED; |
1778 | 1810 | MSAN_MAYBE_INTERCEPT_CFREE;
|
1779 | 1811 | MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE;
|
1780 | 1812 | MSAN_MAYBE_INTERCEPT_MALLINFO;
|
|
0 commit comments