libgit2 / libgit2/libgit2sharp
Consider using SafeHandle in Libgit2Object instead of void*
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
We've had a couple of bug reports against dotnet/runtime with rarely-reproduceable crashes coming from libgit2sharp. We believe that one possible reason could be an interop anti-pattern in Libgit2Object - void*/IntPtr representation of a native handle that can be freed in finalizer. E.g. in this case the finalizer in Libgit2Object may end up calling native free here (and other overloads).
The reason why it's called an anti-pattern can be explained by a short repro in this issue: https://github.com/dotnet/runtime/issues/103522 and a general solution is to use SafeHandle for such handles. Also, see https://learn.microsoft.com/en-us/dotnet/standard/native-interop/best-practices
Reproduction steps
Expected behavior
Actual behavior
Version of LibGit2Sharp (release number or SHA1)
Operating system(s) tested; .NET runtime tested
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
Start in LibGit2Sharp/Core/Handles/Libgit2Object.cs around line 88, then trace the finalizer and native-free overloads in LibGit2Sharp/Core/Handles/Objects.cs around lines 502-505. Compare those ownership paths with the SafeHandle guidance and linked runtime reports. Done means the relevant native handle lifetime paths are safely represented and freed without the reported finalizer race.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- devtools
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100