[BUG] Memory leak: failing `Indexer::new` → the progress payload is never freed

Aperta
#1,347 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
devtools

Direzione di ricerca

The leak is the OdbPackwriterCb box allocated in Indexer::new_ext, which the sanitizer report places in the git2 crate's indexer and odb modules. Start by reading how new_ext builds the callback and what happens on the error return path when the libgit2 indexer creation fails. Run the reproduction under AddressSanitizer. Done means the error is still returned for a nonexistent directory and the LeakSanitizer report no longer appears.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Can be triggered on the latest commit b9d59b6 (git2, vendored-libgit2 feature), from rust safe code (#![forbid(unsafe_code)]).

Summary

Running the program below prints the following and exits with a LeakSanitizer report:

indexer -> Some(Error { code: -1, klass: 2, message: "failed to create temporary file '/nonexistent/git2-idx/pack_git2_58c30172ca8189b1': No such file or directory" })
==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
  #5 <alloc::boxed::Box<git2::odb::OdbPackwriterCb>>::new
  #6 <git2::indexer::Indexer>::new_ext
  #7 <git2::indexer::Indexer>::new

SUMMARY: AddressSanitizer: 16 byte(s) leaked in 1 allocation(s).

Indexer::new returns Err when given a nonexistent output directory, leaving the 16-byte OdbPackwriterCb allocated during Indexer::new leaked at exit.

Reproduce

Cargo.toml:

[dependencies]
git2 = { git = "https://github.com/rust-lang/git2-rs", rev = "b9d59b6", features = ["vendored-libgit2"] }

src/main.rs:

#![forbid(unsafe_code)]
use git2::Indexer;
use std::path::Path;

fn main() {
    let r = Indexer::new(None, Path::new("/nonexistent/git2-idx"), 0, false);
    eprintln!("indexer -> {:?}", r.err());
}
RUSTFLAGS="-Zsanitizer=address" \
  cargo +nightly run -Zbuild-std --target x86_64-unknown-linux-gnu
Lingua principale
Rust
Stelle
2.1k
Fork
470
Merge medio
2g 17h
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/git2-rs

Tutte le issue di rust-lang/git2-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.