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

Abierto
#1,347 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Rust
Estrellas
2.1k
Forks
470
Merge medio
2 d 17 h
PR fusionados (30 d)
18

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/git2-rs

Todos los issues de rust-lang/git2-rs

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.