makeit icon indicating copy to clipboard operation
makeit copied to clipboard

Library leaks memory if initializing field panics

Open Voultapher opened this issue 4 years ago • 0 comments

#[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.

Voultapher avatar Apr 11 '22 18:04 Voultapher