Skip to content

Nested Vec element buffers leak: Vec[Vec[i32]] drop frees the outer buffer only #736

Closed

Description

@ehartford

Repro (no loop involved — plain construction + scope exit):

fn main:
    var outer: Vec[Vec[i32]] = Vec.new()
    var inner: Vec[i32] = Vec.new()
    inner.push(5)
    outer.push(inner)
    print(int_to_string(outer.len()))
WITH_DEBUG_ALLOC=1 with run repro.w
debug-alloc: LEAK addr=... size=16 origin=unknown
debug-alloc: leak count=1

Same leak with a struct in between (type Job { v: Vec[i32] }, Vec[Job]),
and identical under an archived earlier seed, so this is pre-existing, not a
regression from the recent D5/#730 batches.

The 16 bytes are the inner Vec's element buffer: dropping the outer Vec frees
its own buffer but does not run element drop glue that would free each
element's nested buffer. Post-#691 every Vec needs-drop, so element drops
should be emitted here.

Note origin=unknown in the ledger entry — the allocation carries no drop
origin tag, which is itself worth fixing while in this code (the tag is what
makes these reports actionable).

Found while auditing #712's status for the iteration-semantics work.

Activity

  1. ehartford commented on Jul 28, 2026

    @ehartford
    ContributorAuthor

    Closing as invalid after full root-cause — the filing was wrong, twice, and the trail is worth recording.

    The nested-Vec drop glue is CORRECT: emission traces show the outer Vec[Vec[i32]] takes the element-walk path (elem needs_drop=1) and the walk emits. The 16-byte 'leak' reproduces in programs with NO nesting at all — including plain 'print(int_to_string(42))' — and splits into two known allocations:

    1. The int-formatting runtime scratch (with_fmt_i64), a runtime-root allocation already exempted by --debug-alloc-filter=non-root.
    2. The returned str's own buffer: owned strs are currently no-drop by design (the same pre-flip model Campaign: the wide flip — containers own their buffers (POD-element drop elaboration) #691 is migrating containers away from), so every formatted string 'leaks' its bytes. That is Campaign: the wide flip — containers own their buffers (POD-element drop elaboration) #691's remaining scope, not a distinct bug.

    The false alarm existed because both allocations report origin=unknown in the ledger — no origin tag. That tagging gap is the one actionable residue here and is noted on #691. Verified clean: the original nested repro under --debug-alloc-filter=non-root leaks nothing beyond the str-result allocations.

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