diff --git a/tests/corpus/Cargo.toml b/tests/corpus/Cargo.toml index a1bdcd5..d558e13 100644 --- a/tests/corpus/Cargo.toml +++ b/tests/corpus/Cargo.toml @@ -7,6 +7,10 @@ publish = false name = "issue-74" path = "issue-74.rs" +[[bin]] +name = "issue-20" +path = "issue-20.rs" + [[bin]] name = "issue-70" path = "issue-70.rs" diff --git a/tests/corpus/issue-20.rs b/tests/corpus/issue-20.rs new file mode 100644 index 0000000..7d40a0c --- /dev/null +++ b/tests/corpus/issue-20.rs @@ -0,0 +1,10 @@ +extern "C" { + fn malloc(n: usize) -> *mut std::ffi::c_void; + fn free(ptr: *mut std::ffi::c_void); +} + +fn main() { + let ptr = unsafe { malloc(8) }; + unsafe { free(ptr) }; + unsafe { free(ptr) }; +} diff --git a/tests/regression.rs b/tests/regression.rs index 2a4d1ab..e213417 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -27,6 +27,24 @@ fn duplicate_stack_fields() { )); } +/// Issue: [#20] +/// +/// [#20]: https://github.com/jfrimmel/cargo-valgrind/issues/20 +#[test] +fn invalid_free() { + cargo_valgrind() + .arg("run") + .args(TARGET_CRATE) + .arg("--bin=issue-20") + .assert() + .failure() + .stderr(predicates::str::contains("Error Invalid free")) + .stderr(predicates::str::contains( + "is 0 bytes inside a block of size 8 free'd", + )) + .stderr(predicates::str::contains("Info Block was alloc'd at")); +} + /// Issue: [#70] /// /// [#70]: https://github.com/jfrimmel/cargo-valgrind/issues/70