Skip to content

Library leaks memory if initializing field panics #9

@Voultapher

Description

@Voultapher
#[derive(Builder, Debug)]
struct Orange {
    a: String,
    b: String,
}
 
fn main() {
    let orange = Orange::builder()
        .set_a("xxx".into())
        .set_b(panic!())
        .build();
 
    dbg!(orange);
}
cargo +nightly miri run
 
The following memory was leaked: alloc1014 (Rust heap, size: 3, align: 1) {
    78 78 78                                        │ xxx
}

This can be addressed by using a scope guard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions