use std::process::Command;
const MARKER: &str = "RUSTY_ALLOC_DOUBLE_FREE_CHILD";
fn child_double_free() -> ! {
let p = rusty_alloc::alloc::malloc(64);
assert!(!p.is_null(), "child: malloc failed");
unsafe { rusty_alloc::alloc::free(p) };
unsafe { rusty_alloc::alloc::free(p) };
eprintln!("child: second free RETURNED — double free was not detected");
std::process::exit(97);
}
#[test]
fn double_free_aborts_instead_of_corrupting() {
if std::env::var(MARKER).is_ok() {
child_double_free();
}
let exe = std::env::current_exe().expect("current_exe");
let out = Command::new(exe)
.env(MARKER, "1")
.args(["--exact", "double_free_aborts_instead_of_corrupting"])
.output()
.expect("spawn child");
assert!(
!out.status.success(),
"child exited successfully — a double free was accepted silently"
);
assert_ne!(
out.status.code(),
Some(97),
"the second free RETURNED: detection did not fire"
);
}