Skip to content

Option/Result map / and_then / map_err / or_else never retire the subject they decompose — DOUBLE FREE (main: map((v) => v); #1398 branch: every map/and_then) #1424

Closed

Description

@ehartford

Spec: §10.5/§10.6. A combinator moves the payload out of its materialized subject, so the subject must not also free it.

fn main:
    var xs: Vec[i32] = Vec.new()
    xs.push(1)
    let o: Option[Vec[i32]] = Some(xs)
    let m = o.map((v) => v)
    print(m.is_some())

Actual, with build + WITH_DEBUG_ALLOC=1:

Mechanism: lower_option_combinator_method / lower_result_combinator_method (src/MirLower.w) move the payload (move _7<as v0>.f0) into the closure call or the result, and leave the materialized subject's scope-exit drop live (drop(_7) @ scope-exit). A move out of a variant payload registers no reset-on-move.

Expected: true, leak count 0.

The observing combinators (filter, Option.inspect, Result.inspect / inspect_err / context / with_context) are fixed in #1422, which adds retire_decomposed_carrier. The consuming ones need the same retire once closures own their parameter, which means landing alongside #1398's closure change.

Activity

  1. ehartford commented on Sep 23, 2026

    @ehartford
    ContributorAuthor

    Verified 2026-09-23: on the batch-X2 build (main 977e667, which includes #1398, plus #1404, #1418, #1419, #1425), all four repros run clean under run --debug-alloc (leak count=0, no DOUBLE FREE): o.map((v) => v), o.map((v) => v.len()), o.and_then((v) => Some(v.len())), o.filter((v) => v.len() > 0). The same four DOUBLE FREE on #1398's build. The fix is #1425's variant-payload reset-on-move (plus #1422 for filter). Closes when X2 merges; a debug_alloc fixture pinning these exact four lands with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions