diff --git a/profiling/src/allocation/allocation_le83.rs b/profiling/src/allocation/allocation_le83.rs index 506c5b6c38e..ab9472812bc 100644 --- a/profiling/src/allocation/allocation_le83.rs +++ b/profiling/src/allocation/allocation_le83.rs @@ -373,7 +373,9 @@ unsafe fn alloc_prof_prev_alloc(len: size_t) -> *mut c_void { } unsafe fn alloc_prof_orig_alloc(len: size_t) -> *mut c_void { - let heap = zend::zend_mm_get_heap(); + // Safety: `ZEND_MM_STATE.heap` will be initialised in `alloc_prof_rinit()` and custom ZendMM + // handlers are only installed and pointing to this function if initialization was succesful. + let heap = tls_zend_mm_state_get!(heap).unwrap_unchecked(); let (prepare, restore) = tls_zend_mm_state_get!(prepare_restore_zend_heap); let custom_heap = prepare(heap); let ptr: *mut c_void = zend::_zend_mm_alloc(heap, len); @@ -398,7 +400,9 @@ unsafe fn alloc_prof_prev_free(ptr: *mut c_void) { } unsafe fn alloc_prof_orig_free(ptr: *mut c_void) { - let heap = zend::zend_mm_get_heap(); + // Safety: `ZEND_MM_STATE.heap` will be initialised in `alloc_prof_rinit()` and custom ZendMM + // handlers are only installed and pointing to this function if initialization was succesful. + let heap = tls_zend_mm_state_get!(heap).unwrap_unchecked(); zend::_zend_mm_free(heap, ptr); } @@ -432,7 +436,9 @@ unsafe fn alloc_prof_prev_realloc(prev_ptr: *mut c_void, len: size_t) -> *mut c_ } unsafe fn alloc_prof_orig_realloc(prev_ptr: *mut c_void, len: size_t) -> *mut c_void { - let heap = zend::zend_mm_get_heap(); + // Safety: `ZEND_MM_STATE.heap` will be initialised in `alloc_prof_rinit()` and custom ZendMM + // handlers are only installed and pointing to this function if initialization was succesful. + let heap = tls_zend_mm_state_get!(heap).unwrap_unchecked(); let (prepare, restore) = tls_zend_mm_state_get!(prepare_restore_zend_heap); let custom_heap = prepare(heap); let ptr: *mut c_void = zend::_zend_mm_realloc(heap, prev_ptr, len);