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
Box[dyn Trait] never runs the boxed value's Drop and leaks its allocation #1847
A Box[dyn Trait] never runs the boxed value's Drop and leaks the box's allocation (found fixing #1827; verified on b4957bba, the parent of the fix-globals stack).
use std.box.Box
trait Named:
fn name(self: &Self) -> i32
type Tok:
n: i32
impl Named for Tok:
fn name(self: &Self) -> i32: self.n
impl Drop for Tok:
move fn drop(): print(f"drop {self.n}")
fn main:
{
let b: Box[dyn Named] = Box.new(Tok { n: 1 })
print(f"{b.name()}")
}
print("end")
with run --debug-alloc (b4957bba):
1
end
debug-alloc: LEAK addr=4334190608 size=16 origin=with_alloc
debug-alloc: leak count=1
Expected (§2.4: the value is dropped when its owner goes out of scope; With calls a leak a defect): 1, drop 1, end, leak count=0.
Sema's #1827 rule already treats the drop of a dyn Trait value as running any implementor's drop (push_drop_glue_bodies), so a view of a global live across that drop is refused once the drop runs.
Activity
Sema: an implicit drop writes every global its type's Drop impls writ…
Box[dyn Trait] drops what it holds, exactly once, then frees its cell…
Sema/Codegen: a Box[dyn T] parameter takes a Box[C] of any implemento…
test: #1847's and #1854's behavior tests pin drop order and count in …
Sema/MirLower/Codegen: a typed binding pattern over a `&dyn T` subjec…
Sema: a value whose type implements the trait auto-references into a …