Skip to content

Ownership audit accepts duplicate cleanup of a moved enum payload and its carrier #1177

Closed

Description

@ehartford

The cleanup work for #1172 exposed a double drop that audit:all accepts (facts=11504 violations=0 ok). This is related to #1170 but involves moving a projected enum payload, then dropping the enclosing enum after dropping the binding.

Repro:

var drops = 0
type Owned { text: str }
impl Drop for Owned:
    move fn drop(): drops += 1
fn make() -> Option[Owned]: Some(Owned { text: "held".clone() })
fn stop():
    match make():
        Some(value) => { assert(value.text == "held"); return }
        None => return
fn main:
    stop()
    assert(drops == 1)

The assertion fails with the candidate #1172 compiler. Its MIR moves _2<as v0>.f0 into _4, then emits drop(_4) and drop(_2) on the same return path. LLDB stops in MirBuilder.emit_drop_entry with w1=4, w2=0 and then w1=2, w2=0, both from emit_drops_for_return. The second call is at emit_drops_for_return+308. lower_match+1276 lowers the returning arm before lower_match+1480 cancels the carrier's statement cleanup.

The original behav_regex_std.w retained runner binary reports an allocator DOUBLE FREE in Regex.replace_fn: the Captures binding and enclosing Option[Captures] both destroy the same PCRE allocation. Address trap free hit 12 at address 4295840464 reaches Captures.drop at executable address 0x100003884; the duplicate free reaches 0x1000038cc. The line reducer retained an eight-line regex callback reproduction.

Expected: the ownership audit must reject cleanup of an aggregate whose moved payload has not been reset or excluded from that cleanup. It must account for the payload's actual state rather than accepting the aggregate as wholly initialized.

Evidence: out/with-get-investigation/return-temps-match-audit-before.log, return-temps-match-double-drop-lldb.log, return-temps-match-mir.log, return-temps-regex-first-free-lldb.log, and return-temps-regex-address-lldb.log. Filed in the same batch as the lowering repair; the validator root still needs instruction-level investigation.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce.

    $ cat main.w   # the report's Option[Owned] match with return in each arm
    $ with run --debug-alloc main.w
    ok
    debug-alloc: leak count=0 allocations=0
    
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