Skip to content

Commit f2ddfd3

Browse files
fix(profiling): use cached heap in alloc_prof_orig_* functions
A crash report indicated that `_zend_mm_alloc` was being called with an invalid heap pointer This invalid pointer originated from the call to `zend::zend_mm_get_heap()` within `alloc_prof_orig_alloc`.
1 parent 4a26042 commit f2ddfd3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

profiling/src/allocation/allocation_le83.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ unsafe fn alloc_prof_prev_alloc(len: size_t) -> *mut c_void {
373373
}
374374

375375
unsafe fn alloc_prof_orig_alloc(len: size_t) -> *mut c_void {
376-
let heap = zend::zend_mm_get_heap();
376+
// Safety: `ZEND_MM_STATE.heap` will be initialised in `alloc_prof_rinit()` and custom ZendMM
377+
// handlers are only installed and pointing to this function if initialization was succesful.
378+
let heap = tls_zend_mm_state_get!(heap).unwrap_unchecked();
377379
let (prepare, restore) = tls_zend_mm_state_get!(prepare_restore_zend_heap);
378380
let custom_heap = prepare(heap);
379381
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) {
398400
}
399401

400402
unsafe fn alloc_prof_orig_free(ptr: *mut c_void) {
401-
let heap = zend::zend_mm_get_heap();
403+
// Safety: `ZEND_MM_STATE.heap` will be initialised in `alloc_prof_rinit()` and custom ZendMM
404+
// handlers are only installed and pointing to this function if initialization was succesful.
405+
let heap = tls_zend_mm_state_get!(heap).unwrap_unchecked();
402406
zend::_zend_mm_free(heap, ptr);
403407
}
404408

@@ -432,7 +436,9 @@ unsafe fn alloc_prof_prev_realloc(prev_ptr: *mut c_void, len: size_t) -> *mut c_
432436
}
433437

434438
unsafe fn alloc_prof_orig_realloc(prev_ptr: *mut c_void, len: size_t) -> *mut c_void {
435-
let heap = zend::zend_mm_get_heap();
439+
// Safety: `ZEND_MM_STATE.heap` will be initialised in `alloc_prof_rinit()` and custom ZendMM
440+
// handlers are only installed and pointing to this function if initialization was succesful.
441+
let heap = tls_zend_mm_state_get!(heap).unwrap_unchecked();
436442
let (prepare, restore) = tls_zend_mm_state_get!(prepare_restore_zend_heap);
437443
let custom_heap = prepare(heap);
438444
let ptr: *mut c_void = zend::_zend_mm_realloc(heap, prev_ptr, len);

0 commit comments

Comments
 (0)