| 2920 | } |
| 2921 | |
| 2922 | JEMALLOC_ALWAYS_INLINE void |
| 2923 | isfree(tsd_t *tsd, void *ptr, size_t usize, tcache_t *tcache, bool slow_path) { |
| 2924 | if (!slow_path) { |
| 2925 | tsd_assert_fast(tsd); |
| 2926 | } |
| 2927 | check_entry_exit_locking(tsd_tsdn(tsd)); |
| 2928 | if (tsd_reentrancy_level_get(tsd) != 0) { |
| 2929 | assert(slow_path); |
| 2930 | } |
| 2931 | |
| 2932 | assert(ptr != NULL); |
| 2933 | assert(malloc_initialized() || IS_INITIALIZER); |
| 2934 | |
| 2935 | emap_alloc_ctx_t alloc_ctx; |
| 2936 | if (!config_prof) { |
| 2937 | alloc_ctx.szind = sz_size2index(usize); |
| 2938 | alloc_ctx.slab = (alloc_ctx.szind < SC_NBINS); |
| 2939 | } else { |
| 2940 | if (likely(!prof_sample_aligned(ptr))) { |
| 2941 | /* |
| 2942 | * When the ptr is not page aligned, it was not sampled. |
| 2943 | * usize can be trusted to determine szind and slab. |
| 2944 | */ |
| 2945 | alloc_ctx.szind = sz_size2index(usize); |
| 2946 | alloc_ctx.slab = (alloc_ctx.szind < SC_NBINS); |
| 2947 | } else if (opt_prof) { |
| 2948 | emap_alloc_ctx_lookup(tsd_tsdn(tsd), &arena_emap_global, |
| 2949 | ptr, &alloc_ctx); |
| 2950 | |
| 2951 | if (config_opt_safety_checks) { |
| 2952 | /* Small alloc may have !slab (sampled). */ |
| 2953 | if (unlikely(alloc_ctx.szind != |
| 2954 | sz_size2index(usize))) { |
| 2955 | safety_check_fail_sized_dealloc( |
| 2956 | /* current_dealloc */ true, ptr, |
| 2957 | /* true_size */ sz_index2size( |
| 2958 | alloc_ctx.szind), |
| 2959 | /* input_size */ usize); |
| 2960 | } |
| 2961 | } |
| 2962 | } else { |
| 2963 | alloc_ctx.szind = sz_size2index(usize); |
| 2964 | alloc_ctx.slab = (alloc_ctx.szind < SC_NBINS); |
| 2965 | } |
| 2966 | } |
| 2967 | bool fail = maybe_check_alloc_ctx(tsd, ptr, &alloc_ctx); |
| 2968 | if (fail) { |
| 2969 | /* |
| 2970 | * This is a heap corruption bug. In real life we'll crash; for |
| 2971 | * the unit test we just want to avoid breaking anything too |
| 2972 | * badly to get a test result out. Let's leak instead of trying |
| 2973 | * to free. |
| 2974 | */ |
| 2975 | return; |
| 2976 | } |
| 2977 | |
| 2978 | if (config_prof && opt_prof) { |
| 2979 | prof_free(tsd, ptr, usize, &alloc_ctx); |
no test coverage detected