Skip to content

Commit 4bb3f84

Browse files
committed
fix realloc counting
1 parent f2548a0 commit 4bb3f84

File tree

1 file changed

+4
-1
lines changed
  • turbopack/crates/turbo-tasks-malloc/src

1 file changed

+4
-1
lines changed

turbopack/crates/turbo-tasks-malloc/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ unsafe impl GlobalAlloc for TurboMalloc {
135135
let old_size = unsafe { base_alloc_size(ptr, layout) };
136136
let ret = unsafe { base_alloc().realloc(ptr, layout, new_size) };
137137
if !ret.is_null() {
138-
let new_size = unsafe { base_alloc_size(ret, layout) };
138+
// SAFETY: the caller must ensure that the `new_size` does not overflow.
139+
// `layout.align()` comes from a `Layout` and is thus guaranteed to be valid.
140+
let new_layout = unsafe { Layout::from_size_align_unchecked(new_size, layout.align()) };
141+
let new_size = unsafe { base_alloc_size(ret, new_layout) };
139142
update(old_size, new_size);
140143
}
141144
ret

0 commit comments

Comments
 (0)