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
{{ message }}
Repository navigation
Result[T]::unwrap() double-frees when T has a Drop impl (e.g. CString) #648
Result[T, E].unwrap() double-frees when T owns a resource (has an impl Drop). str.to_cstring().unwrap() panics with invalid free: pointer is not an allocated payload start — the recovered CString is dropped twice (the moved-out value and the Result's copy).
Repro (verified on the seed and HEAD)
fn main:
let c = "hi".to_cstring().unwrap() // panic: invalid free
print_i32(c.len() as i32)
match "hi".to_cstring(): .Ok(c) => ... works (2).
Direct CString { ptr, len } construct + drop works (1).
Vec (also Drop) round-trips fine, so it is specific to unwrap's move of the payload out of the Result — the Result's Ok payload is not marked consumed, so both drop.
Spec
§9.x Result / §2.5 ownership: unwrap consumes the Result and moves the payload out; the payload must be dropped exactly once.
Impact
Any Result[DropType]::unwrap() / likely expect() and possibly ? on a Result[DropType] double-frees. Surfaced building the #602retains: owned-argument path (worked around with match).
Activity
Fix #602: retained C-string params (retains:) reject a call-scoped st…