You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(observability): fix panic in allocation tracing when deallocating pre-tracking memory
When `--allocation-tracing` is enabled at runtime, the custom allocator
wraps every allocation with an extra byte to store the allocation group
ID. Previously, allocations made before tracking was enabled used the
original (unwrapped) layout. When those were later freed, `dealloc`
read an out-of-bounds byte as the group ID, hitting
`NonZeroU8::new_unchecked(0)` -- undefined behavior that recent Rust
toolchains (>= ~1.78) turn into an abort in debug builds.
Additionally, reentrant allocations (wrapped layout but tracing closure
skipped) left the group ID header uninitialized, causing misattributed
deallocations and skewed per-group memory accounting.
Fix: always allocate with the wrapped layout, regardless of whether
tracking is currently enabled. The group ID header byte is set to:
- UNTRACKED (0): tracking was off at allocation time
- UNTRACED (u8::MAX): tracking was on but the tracing closure was
skipped due to reentrancy
- A real group ID (1..254): normal traced allocation
On deallocation, all paths free with the wrapped layout (which is
always correct now). UNTRACKED and UNTRACED skip `trace_deallocation`
to keep per-group accounting balanced.
This eliminates:
- The original panic/UB from `NonZero::new_unchecked(0)`
- Layout mismatches for pre-tracking allocations (including realloc)
- Accounting skew from uninitialized headers on reentrant allocations
This bug has been latent since #15221 (Nov 2022) which introduced the
runtime toggle.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixed a panic (abort) when running with `--allocation-tracing` in debug builds, caused by deallocating memory that was allocated before tracking was enabled. Also fixed per-group memory accounting skew for reentrant allocations whose tracing closure was skipped, which left the group ID header uninitialized and caused deallocations to be attributed to wrong groups.
0 commit comments