diff --git a/.rustsec-ignore.txt b/.rustsec-ignore.txt index 4bd22dd..8ef81c4 100644 --- a/.rustsec-ignore.txt +++ b/.rustsec-ignore.txt @@ -9,3 +9,11 @@ RUSTSEC-2024-0384 # adler 1.0.2 affected by RUSTSEC-2025-0056 (unmaintained) # -> only used for anyhow backtraces RUSTSEC-2025-0056 + +# crossbeam-epoch 0.9.18 affected by RUSTSEC-2026-0204 (Invalid +# pointer dereference in `fmt::Pointer` impl for `Atomic` and `Shared` +# when the underlying pointer is invalid) +# +# XXX should look into this. Affected versions: >=0.9.0, <0.9.20, and +# 0.9.20 is just 1 month old, thus have to review. +RUSTSEC-2026-0204 diff --git a/Cargo.lock b/Cargo.lock index 965f337..a716c24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -346,6 +346,24 @@ dependencies = [ "adler", ] +[[package]] +name = "mockalloc" +version = "0.1.2" +source = "git+https://github.com/diggsey/mockalloc?rev=103439477d7e6acccef3c203730ed3009f3dec41#103439477d7e6acccef3c203730ed3009f3dec41" +dependencies = [ + "mockalloc-macros", +] + +[[package]] +name = "mockalloc-macros" +version = "0.1.0" +source = "git+https://github.com/diggsey/mockalloc?rev=103439477d7e6acccef3c203730ed3009f3dec41#103439477d7e6acccef3c203730ed3009f3dec41" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "nix" version = "0.24.3" @@ -490,6 +508,7 @@ dependencies = [ "clap-with-warnings", "derive_more", "lazy_static", + "mockalloc", "patchparser", "rayon", "regex", diff --git a/Cargo.toml b/Cargo.toml index c94c6a9..5f9978b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,6 @@ clap = { version = "4", features = ["derive"] } clap-with-warnings = { version = "0.1.4" } derive_more = { version = "2.0.1", features = ["from", "from_str"] } lazy_static = "1.4" +mockalloc = { git = "https://github.com/diggsey/mockalloc", rev = "103439477d7e6acccef3c203730ed3009f3dec41" } rayon = "1.10.0" regex = "1.4.6" diff --git a/Makefile b/Makefile index 187bd92..fed5bb6 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ test_integration_opt: test: cargo_test test_integration leak_test: - RUSTFLAGS="-Z sanitizer=leak" OUR_CARGO_FLAGS=+nightly make test + make test test_deny_warnings: RUSTFLAGS="--deny warnings" make cargo_test diff --git a/src/bin/test-split-patches-in-dir.rs b/src/bin/test-split-patches-in-dir.rs index 1cc74f1..a69bbc8 100644 --- a/src/bin/test-split-patches-in-dir.rs +++ b/src/bin/test-split-patches-in-dir.rs @@ -1,4 +1,5 @@ use std::{ + alloc::System, fs::{self, File}, io::{BufWriter, Write}, os::unix::ffi::OsStrExt, @@ -9,11 +10,15 @@ use std::{ use anyhow::anyhow; use anyhow::{Context, Ok, Result}; use clap_with_warnings::clap_with_warnings; +use mockalloc::Mockalloc; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use split_patch::{ core::split_patch, path_utils::path_remove_common_lead, split_options::SplitArgs, }; +#[global_allocator] +static ALLOCATOR: Mockalloc = Mockalloc(System); + /// Test split patches in directory. /// /// For all files in `input-dir`, split them with `split-patch` into @@ -32,7 +37,7 @@ pub struct TestArgs { output_base: PathBuf, } -fn main() -> Result<()> { +fn main_() -> Result<()> { let args = TestArgs::parse(); let mut patch_files: Vec = args @@ -140,3 +145,24 @@ fn main() -> Result<()> { Ok(()) } + +fn main() { + let mut exit_code = 0; + // assert_allocs does not allow non-() returns; makes sense since + // those allocations would be leaks and lead to a panic. But don't + // want to exit inside. Thus, pass the integer value out, let it + // check, then exit. + mockalloc::assert_allocs(|| { + // Need to set up our own rayon thread pool to ensure that it + // is being shut down before doing the leak check. + let pool = rayon::ThreadPoolBuilder::new() + .build().unwrap(); + pool.install(|| { + if let Err(e) = main_() { + eprintln!("Error: {e:#}"); + exit_code = 1; + } + }); + }); + exit(exit_code); +}