[BUG] Memory leak: calling `PackBuilder::write` → the progress payload is leaked on every call

Đang mở
#1,348 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
git, rust
Lĩnh vực
devtools

Hướng nghiên cứu

Start from PackBuilder::write and OdbPackwriterCb::new, which the leak report names as the allocation site. Check how the boxed callback is passed to libgit2 and whether it is reclaimed on both the error path and the success path. Done when the reproducer runs under LeakSanitizer with no reported leak and the existing tests still pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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:

write(bad) -> Err(Error { code: -1, klass: 2, message: "failed to create temporary file '/nonexistent/git2-pb/pack_git2_cb83dc77581f119a': No such file or directory" })
write(ok) -> Ok(())
==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::packbuilder::PackBuilder>::write
  #7 main

Direct leak of 16 byte(s) in 1 object(s) allocated from:
  #5 <alloc::boxed::Box<git2::odb::OdbPackwriterCb>>::new
  #6 <git2::packbuilder::PackBuilder>::write
  #7 main

SUMMARY: AddressSanitizer: 32 byte(s) leaked in 2 allocation(s).

Both the failing pb.write call and the succeeding pb.write call leave a leaked 16-byte OdbPackwriterCb allocation behind even after pb and repo are dropped.

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::Repository;
use std::path::Path;

fn main() -> Result<(), git2::Error> {
    let dir = std::env::temp_dir().join(format!("git2-pb-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&dir);
    let repo = Repository::init_bare(&dir)?;
    let oid = repo.blob(b"hello")?;
    let mut pb = repo.packbuilder()?;
    pb.insert_object(oid, None)?;
    eprintln!("write(bad) -> {:?}", pb.write(Path::new("/nonexistent/git2-pb"), 0));
    eprintln!("write(ok) -> {:?}", pb.write(&dir, 0));
    drop(pb);
    drop(repo);
    let _ = std::fs::remove_dir_all(&dir);
    Ok(())
}
RUSTFLAGS="-Zsanitizer=address" \
  cargo +nightly run -Zbuild-std --target x86_64-unknown-linux-gnu
Ngôn ngữ chính
Rust
Star
2.1k
Fork
470
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
18

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/git2-rs

Tất cả issue của rust-lang/git2-rs

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.