estebank / makeit

Zero-overhead type-safe builder pattern `derive` macro for your Rust structs
223 stars 11 forks source link

Library leaks memory if initializing field panics #9

Open Voultapher opened 2 years ago

Voultapher commented 2 years ago
#[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.