Skip to content

Commit d6282d3

Browse files
committed
Properly implement disposable for Remote
1 parent 53b66be commit d6282d3

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

LibGit2Sharp/Remote.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace LibGit2Sharp
1212
/// A remote repository whose branches are tracked.
1313
/// </summary>
1414
[DebuggerDisplay("{DebuggerDisplay,nq}")]
15-
public class Remote : IEquatable<Remote>, IBelongToARepository
15+
public class Remote : IEquatable<Remote>, IBelongToARepository, IDisposable
1616
{
1717
private static readonly LambdaEqualityHelper<Remote> equalityHelper =
1818
new LambdaEqualityHelper<Remote>(x => x.Name, x => x.Url, x => x.PushUrl);
@@ -43,12 +43,37 @@ internal Remote(RemoteSafeHandle handle, Repository repository)
4343

4444
~Remote()
4545
{
46-
if (handle != null)
46+
Dispose(false);
47+
}
48+
49+
#region IDisposable
50+
51+
bool disposedValue = false; // To detect redundant calls
52+
53+
/// <summary>
54+
/// Release the unmanaged remote object
55+
/// </summary>
56+
public void Dispose()
57+
{
58+
Dispose(true);
59+
GC.SuppressFinalize(this);
60+
}
61+
62+
void Dispose(bool disposing)
63+
{
64+
if (!disposedValue)
4765
{
48-
handle.Dispose();
66+
if (handle != null)
67+
{
68+
handle.Dispose();
69+
}
70+
71+
disposedValue = true;
4972
}
5073
}
5174

75+
#endregion
76+
5277
/// <summary>
5378
/// Gets the alias of this remote repository.
5479
/// </summary>

0 commit comments

Comments
 (0)