Skip to content

Missing cleanup on escape from functional record update #21486

Closed
@arielb1

Description

@arielb1

I was playing around with #21407, and I think I found a distinct bug in FRU – if a field initialiser escapes (panics/returns/breaks), some of the fields in the original struct get leaked.

For example:

struct Noisy(u32);
impl Drop for Noisy {
    fn drop(&mut self) {
        println!("splat #{}!", self.0);
    }
}

struct Foo { n0: Noisy, n1: Noisy }

fn leak() -> Foo {
    let old_foo = Foo { n0: Noisy(0), n1: Noisy(1) };
    Foo { n0: { return Foo { n0: Noisy(3), n1: Noisy(4) } }, ..old_foo } ;
}

fn main() {
    drop(leak());
}

This prints

splat #0!
splat #3!
splat #4!

Observe that the Noisy(1) is never destroyed.

Metadata

Metadata

Assignees

Labels

E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priority

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions