{"id":17168586,"url":"https://github.com/jfrimmel/cargo-valgrind","last_synced_at":"2025-05-15T20:03:40.412Z","repository":{"id":35054655,"uuid":"199844652","full_name":"jfrimmel/cargo-valgrind","owner":"jfrimmel","description":"A cargo subcommand, that runs valgrind and displays its output in a helpful manner. Tailored to Rust.","archived":false,"fork":false,"pushed_at":"2025-04-06T09:59:47.000Z","size":299,"stargazers_count":143,"open_issues_count":5,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T02:39:17.463Z","etag":null,"topics":["cargo","cargo-plugin","cargo-subcommand","cargo-valgrind","ffi","ffi-bindings","leak","runs-valgrind","rust","rust-valgrind","valgrind"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/cargo-valgrind","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jfrimmel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-31T11:41:18.000Z","updated_at":"2025-04-06T09:59:51.000Z","dependencies_parsed_at":"2025-01-04T19:02:45.703Z","dependency_job_id":"15a0094d-fd74-4b8c-ad8a-b0471028f55d","html_url":"https://github.com/jfrimmel/cargo-valgrind","commit_stats":{"total_commits":206,"total_committers":10,"mean_commits":20.6,"dds":0.08252427184466016,"last_synced_commit":"094d3a1446c63ab3443291fb3d26da4da91d370a"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfrimmel%2Fcargo-valgrind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfrimmel%2Fcargo-valgrind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfrimmel%2Fcargo-valgrind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfrimmel%2Fcargo-valgrind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jfrimmel","download_url":"https://codeload.github.com/jfrimmel/cargo-valgrind/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414493,"owners_count":22067271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cargo","cargo-plugin","cargo-subcommand","cargo-valgrind","ffi","ffi-bindings","leak","runs-valgrind","rust","rust-valgrind","valgrind"],"created_at":"2024-10-14T23:12:16.115Z","updated_at":"2025-05-15T20:03:38.379Z","avatar_url":"https://github.com/jfrimmel.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `cargo-valgrind`\n\u003e A cargo subcommand, that runs valgrind and collects its output in a helpful manner.\n\n[![Latest version](https://img.shields.io/crates/v/cargo-valgrind.svg)](https://crates.io/crates/cargo-valgrind)\n[![Latest GitHub release](https://img.shields.io/github/v/release/jfrimmel/cargo-valgrind)](https://github.com/jfrimmel/cargo-valgrind/releases/latest)\n![License](https://img.shields.io/crates/l/cargo-valgrind)\n[![Crates.io Total Downloads](https://img.shields.io/crates/d/cargo-valgrind)](https://crates.io/crates/cargo-valgrind)\n\n\nThis command extends cargo with the capability to directly run `valgrind` on any crate executable.\nThe output of valgrind is then used to mark the binary as pass/fail.\n\nThis command should not be necessary for ordinary Rust programs, especially if you are only using safe Rust code.\nBut if you do FFI-related stuff (either by simply using a FFI-binding crate or because you are developing a safe wrapper for such FFI bindings) it may be really helpful to check, whether the memory usages across the FFI borders are correct.\n\n## Usage\nA typical mistake would be:\n```rust\nuse std::ffi::CString;\nuse std::os::raw::c_char;\n\nextern \"C\" {\n    fn puts(s: *const c_char);\n}\n\nfn main() {\n    let string = CString::new(\"Test\").unwrap();\n\n    let ptr = string.into_raw();\n    unsafe { puts(ptr) };\n\n    // unsafe { CString::from_raw(ptr) };\n}\n```\nThe memory of the variable `string` will never be freed.\nIf you run `cargo valgrind run` in your shell, it detects the leak:\n```bash\n$ cargo valgrind run\n    Finished dev [unoptimized + debuginfo] target(s) in 0.01s\n     Running `target/debug/cstring`\nTest\n       Error leaked 5 B in 1 block\n        Info stack trace (user code at the bottom)\n             at malloc (vg_replace_malloc.c:446)\n             at alloc (alloc.rs:100)\n             at alloc_impl (alloc.rs:183)\n             at allocate (alloc.rs:243)\n             at try_allocate_in\u003cu8, alloc::alloc::Global\u003e (raw_vec.rs:230)\n             at with_capacity_in\u003cu8, alloc::alloc::Global\u003e (raw_vec.rs:158)\n             at with_capacity_in\u003cu8, alloc::alloc::Global\u003e (mod.rs:699)\n             at with_capacity\u003cu8\u003e (mod.rs:481)\n             at spec_new_impl_bytes (c_str.rs:290)\n             at \u003c\u0026str as alloc::ffi::c_str::CString::new::SpecNewImpl\u003e::spec_new_impl (c_str.rs:309)\n             at alloc::ffi::c_str::CString::new (c_str.rs:319)\n             at ffi_bug::main (main.rs:9)\n             at core::ops::function::FnOnce::call_once (function.rs:250)\n             at std::sys::backtrace::__rust_begin_short_backtrace (backtrace.rs:152)\n             at std::rt::lang_start::{{closure}} (rt.rs:162)\n             at call_once\u003c(), (dyn core::ops::function::Fn\u003c(), Output=i32\u003e + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)\u003e (function.rs:284)\n             at do_call\u003c\u0026(dyn core::ops::function::Fn\u003c(), Output=i32\u003e + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32\u003e (panicking.rs:557)\n             at try\u003ci32, \u0026(dyn core::ops::function::Fn\u003c(), Output=i32\u003e + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)\u003e (panicking.rs:521)\n             at catch_unwind\u003c\u0026(dyn core::ops::function::Fn\u003c(), Output=i32\u003e + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32\u003e (panic.rs:350)\n             at {closure#2} (rt.rs:141)\n             at do_call\u003cstd::rt::lang_start_internal::{closure_env#2}, isize\u003e (panicking.rs:557)\n             at try\u003cisize, std::rt::lang_start_internal::{closure_env#2}\u003e (panicking.rs:521)\n             at catch_unwind\u003cstd::rt::lang_start_internal::{closure_env#2}, isize\u003e (panic.rs:350)\n             at std::rt::lang_start_internal (rt.rs:141)\n             at std::rt::lang_start (rt.rs:161)\n             at main\n     Summary Leaked 5 B total (0 other errors)\n```\nUn-commenting the `unsafe { CString::from_raw(ptr) };` re-takes the memory and frees it correctly.\n`cargo valgrind run` will compile the binary for you and won't detect a leak, since there is no leak anymore.\n\nIf you would like to pass flags to valgrind (for example to run an alternate subtool), you can set the `VALGRINDFLAGS` environment variable to a space-delimited list of valid Valgrind options.\n\n`cargo valgrind` automatically applies some suppressions for wrongly reported leaks within the Rust standard library.\nThis makes the tool more powerful than a normal valgrind invocation.\n\n_Note_: users of `cargo-valgrind` version 1.x should mind the changed command line.\nPreviously there was a `cargo valgrind` subcommand, that replaced the `cargo run` or `cargo test` commands.\nNow the command line is `cargo valgrind \u003ccommand\u003e`, where `\u003ccommand\u003e` can be any normal cargo subcommand.\n\n# Installation\n## Requirements\nYou need to have `valgrind` installed and in the `PATH` (you can test this by running `valgrind --help` in your shell).\n\nYou'll also need to have `cargo` installed and in the `PATH`, but since this is a cargo subcommand, you will almost certainly have it already installed.\n\n## Install the binary\n### Use pre-built binaries\nHead over to the [latest release] and download the artifact for your platform.\nThe binary has to be extracted into the `.cargo`-directory, typically under `$HOME/.cargo`.\nNote, that it is not possible to directly run the program itself, as it must be invoked via `cargo valgrind`, so it must be located in a directory, `cargo` searches its subcommands in.\n\n[latest release]: https://github.com/jfrimmel/cargo-valgrind/releases/latest\n\n### From Source\nRun the following command to install from [crates.io](https://crates.io/crates/cargo-valgrind):\n```bash\n$ cargo install cargo-valgrind\n```\nThis will install the latest official released version.\n\nIf you want to use the latest changes, that were not yet published to `crates.io`, you can install the binary from the git-repository like this:\n```bash\n$ cargo install --git https://github.com/jfrimmel/cargo-valgrind\n```\n\n# License\nLicensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or [MIT license](LICENSE-MIT) at your option.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `cargo-valgrind` by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfrimmel%2Fcargo-valgrind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjfrimmel%2Fcargo-valgrind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfrimmel%2Fcargo-valgrind/lists"}