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
Option.filter passes the payload BY VALUE to the predicate and then keeps it — double free #1379
Spec: §10 Option table — filter | (fn(&T) -> bool) -> Option[T]. The predicate observes; it must receive &T.
fn main:
var xs: Vec[i32] = Vec.new()
xs.push(1)
let o: Option[Vec[i32]] = Some(xs)
let m = o.filter((v) => v.len() > 0)
print(m.is_some())
with run --debug-alloc: prints true, then debug-alloc: DOUBLE FREE addr=... size=32 origin=unknown first_drop=<untagged> second_drop=drop#enum __drop_enum_448, rc=134.
Cause (src/MirLower.w lower_option_combinator_method, the filter branch): filter_args.push(self.operand_for_place(payload_place, payload_ty)) moves the payload into the predicate call (the comment there says Sema types the predicate parameter OWNED), and kept_fields.push(self.operand_for_place(payload_place, payload_ty)) moves the same payload again into the result. The predicate frees it on return; the result owns freed memory.
Expected: the predicate parameter is &T (Sema and MIR), the payload moves once, into the kept Some.
Found while building the #1363 matrix (same class: a payload moved out of a carrier twice / after its owner frees it).
Activity
Option.filter's predicate observes `&T`; filter / inspect / context r…
Restore Vec.clone in drop-state storage; pin the cross-unit receiver …