Handle free double-frees memory
Review this Rust FFI shim that hands a boxed handle to C and reclaims it.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 26 min
Mark a line and say what kind of problem it is.0 findings
1#[no_mangle]
2pub extern "C" fn handle_new() -> *mut Conn {
3 Box::into_raw(Box::new(Conn::open()))
4}
5
6#[no_mangle]
7pub extern "C" fn handle_free(p: *mut Conn) {
8 if p.is_null() { return; }
9 unsafe {
10 let _ = Box::from_raw(p); // reconstruct & drop
11 drop(Box::from_raw(p)); // ensure dropped
12 }
13}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.