[BUG] Memory leak: calling `PackBuilder::write` → the progress payload is leaked on every call
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Rust
- 星标
- 2.1k
- 派生
- 470
- 平均合并
- 2 天 17 小时
- 30 天内合并 PR
- 18
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/git2-rs 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 message可能已有人在做 @shivampwm2020 于 43 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 64/100
维护者通常 1 天内回复
查看 rust-lang/git2-rs 的全部 Issue
相似的 Issue
-
bug P2
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
Windows microphone listing treats words in a device name as DirectShow labels可能已有人在做 @Sujal-chaudhary 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 88/100
clipy-recorder/clipy#447 · 2 条评论 ·
维护者通常 1 天内回复
-
nightly-cleanup
难度 2/5 1-3 小时 新手友好度 78/100
max-sixty/worktrunk#4939 · 1 个 reaction ·
维护者通常 1 天内回复
-
flaky
难度 2/5 1-3 小时 新手友好度 68/100
stacks-network/stacks-core#7918 · 1 条评论 ·
维护者通常 2 天内回复