Skip to content

Commit 1c1f012

Browse files
committed
Fix leaked handle in Commit
1 parent e701c25 commit 1c1f012

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

LibGit2Sharp/Commit.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ private IEnumerable<Commit> RetrieveParentsOfCommit(ObjectId oid)
121121

122122
for (uint i = 0; i < parentsCount; i++)
123123
{
124-
GitObjectSafeHandle parentCommit;
125-
Ensure.Success(NativeMethods.git_commit_parent(out parentCommit, obj.ObjectPtr, i));
126-
yield return BuildFromPtr(parentCommit, ObjectIdOf(parentCommit), repo);
124+
using (var parentCommit = GetParentCommitHandle(i, obj))
125+
{
126+
yield return BuildFromPtr(parentCommit, ObjectIdOf(parentCommit), repo);
127+
}
127128
}
128129
}
129130
}
@@ -146,6 +147,13 @@ internal static Commit BuildFromPtr(GitObjectSafeHandle obj, ObjectId id, Reposi
146147
};
147148
}
148149

150+
private static GitObjectSafeHandle GetParentCommitHandle(uint i, ObjectSafeWrapper obj)
151+
{
152+
GitObjectSafeHandle parentCommit;
153+
Ensure.Success(NativeMethods.git_commit_parent(out parentCommit, obj.ObjectPtr, i));
154+
return parentCommit;
155+
}
156+
149157
private static string RetrieveEncodingOf(GitObjectSafeHandle obj)
150158
{
151159
string encoding = NativeMethods.git_commit_message_encoding(obj);

0 commit comments

Comments
 (0)