Diff::merge() causes double free
Open
Nobody has claimed this yet.
upstream
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 450
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
The library fails with a double free when merging two Diff's built from buffers. Is this intended to be supported?
Cargo.toml
[dependencies.git2]
version = "0.17.2"
default-features = false
features = ["vendored-libgit2"]
use git2;
let diff_a: &str = r#"
diff --git a/README.md b/README.md
index 18fb8328..ce60f40c 100644
--- a/README.md
+++ b/README.md
@@ -4,1 +4,2 @@ componentwise
reusing
+proverb
"#
.trim_start();
let mut diff_a = git2::Diff::from_buffer(diff_a.as_bytes()).unwrap();
let diff_b: &str = r#"
diff --git a/README.md b/README.md
index 18fb8328..ce60f40c 100644
--- a/README.md
+++ b/README.md
@@ -4,2 +4,3 @@ componentwise
reusing
proverb
+offended
"#
.trim_start();
let diff_b = git2::Diff::from_buffer(diff_b.as_bytes()).unwrap();
diff_a.merge(&diff_b).expect("merge diff from buffers");
Results in:
free(): double free detected in tcache 2
error: test failed, to rerun pass `-p radicle-cli --lib`
Edit: simplified example and added Cargo information
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the Rust example using git2::Diff::from_buffer and Diff::merge, then inspect those entry points and their ownership behavior. Done means merging two buffer-created diffs no longer triggers a double free, with a regression test covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100