| 2803 | } |
| 2804 | |
| 2805 | JEMALLOC_ALWAYS_INLINE |
| 2806 | bool free_fastpath(void *ptr, size_t size, bool size_hint) { |
| 2807 | tsd_t *tsd = tsd_get(false); |
| 2808 | if (unlikely(!tsd || !tsd_fast(tsd))) { |
| 2809 | return false; |
| 2810 | } |
| 2811 | |
| 2812 | tcache_t *tcache = tsd_tcachep_get(tsd); |
| 2813 | |
| 2814 | alloc_ctx_t alloc_ctx; |
| 2815 | /* |
| 2816 | * If !config_cache_oblivious, we can check PAGE alignment to |
| 2817 | * detect sampled objects. Otherwise addresses are |
| 2818 | * randomized, and we have to look it up in the rtree anyway. |
| 2819 | * See also isfree(). |
| 2820 | */ |
| 2821 | if (!size_hint || config_cache_oblivious) { |
| 2822 | rtree_ctx_t *rtree_ctx = tsd_rtree_ctx(tsd); |
| 2823 | bool res = rtree_szind_slab_read_fast(tsd_tsdn(tsd), &extents_rtree, |
| 2824 | rtree_ctx, (uintptr_t)ptr, |
| 2825 | &alloc_ctx.szind, &alloc_ctx.slab); |
| 2826 | |
| 2827 | /* Note: profiled objects will have alloc_ctx.slab set */ |
| 2828 | if (!res || !alloc_ctx.slab) { |
| 2829 | return false; |
| 2830 | } |
| 2831 | assert(alloc_ctx.szind != SC_NSIZES); |
| 2832 | } else { |
| 2833 | /* |
| 2834 | * Check for both sizes that are too large, and for sampled objects. |
| 2835 | * Sampled objects are always page-aligned. The sampled object check |
| 2836 | * will also check for null ptr. |
| 2837 | */ |
| 2838 | if (size > SC_LOOKUP_MAXCLASS || (((uintptr_t)ptr & PAGE_MASK) == 0)) { |
| 2839 | return false; |
| 2840 | } |
| 2841 | alloc_ctx.szind = sz_size2index_lookup(size); |
| 2842 | } |
| 2843 | |
| 2844 | if (unlikely(ticker_trytick(&tcache->gc_ticker))) { |
| 2845 | return false; |
| 2846 | } |
| 2847 | |
| 2848 | cache_bin_t *bin = tcache_small_bin_get(tcache, alloc_ctx.szind); |
| 2849 | cache_bin_info_t *bin_info = &tcache_bin_info[alloc_ctx.szind]; |
| 2850 | if (!cache_bin_dalloc_easy(bin, bin_info, ptr)) { |
| 2851 | return false; |
| 2852 | } |
| 2853 | |
| 2854 | if (config_stats) { |
| 2855 | size_t usize = sz_index2size(alloc_ctx.szind); |
| 2856 | *tsd_thread_deallocatedp_get(tsd) += usize; |
| 2857 | } |
| 2858 | |
| 2859 | return true; |
| 2860 | } |
| 2861 | |
| 2862 | JEMALLOC_EXPORT void JEMALLOC_NOTHROW |
no test coverage detected