Skip to content

Commit

Permalink
Add a regression test for #20
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrimmel committed Sep 17, 2024
1 parent aa07a4e commit 8e4c064
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/corpus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 10 additions & 0 deletions tests/corpus/issue-20.rs
Original file line number Diff line number Diff line change
@@ -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) };
}
18 changes: 18 additions & 0 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e4c064

Please sign in to comment.