@@ -26,7 +26,7 @@ public class Repository : IDisposable
26
26
private readonly Diff diff ;
27
27
private readonly NoteCollection notes ;
28
28
private readonly Lazy < ObjectDatabase > odb ;
29
- private readonly Stack < SafeHandleBase > handlesToCleanup = new Stack < SafeHandleBase > ( ) ;
29
+ private readonly Stack < IDisposable > toCleanup = new Stack < IDisposable > ( ) ;
30
30
private static readonly Lazy < string > versionRetriever = new Lazy < string > ( RetrieveVersion ) ;
31
31
32
32
/// <summary>
@@ -89,7 +89,7 @@ public Repository(string path, RepositoryOptions options = null)
89
89
branches = new BranchCollection ( this ) ;
90
90
tags = new TagCollection ( this ) ;
91
91
info = new Lazy < RepositoryInformation > ( ( ) => new RepositoryInformation ( this , isBare ) ) ;
92
- config = new Lazy < Configuration > ( ( ) => new Configuration ( this ) ) ;
92
+ config = new Lazy < Configuration > ( ( ) => RegisterForCleanup ( new Configuration ( this ) ) ) ;
93
93
remotes = new Lazy < RemoteCollection > ( ( ) => new RemoteCollection ( this ) ) ;
94
94
odb = new Lazy < ObjectDatabase > ( ( ) => new ObjectDatabase ( this ) ) ;
95
95
diff = new Diff ( this ) ;
@@ -244,9 +244,9 @@ public void Dispose()
244
244
/// </summary>
245
245
protected virtual void Dispose ( bool disposing )
246
246
{
247
- while ( handlesToCleanup . Count > 0 )
247
+ while ( toCleanup . Count > 0 )
248
248
{
249
- handlesToCleanup . Pop ( ) . SafeDispose ( ) ;
249
+ toCleanup . Pop ( ) . SafeDispose ( ) ;
250
250
}
251
251
}
252
252
@@ -481,9 +481,10 @@ public void Reset(ResetOptions resetOptions, string shaOrReferenceName)
481
481
throw new NotImplementedException ( ) ;
482
482
}
483
483
484
- internal void RegisterForCleanup ( SafeHandleBase handleToCleanup )
484
+ internal T RegisterForCleanup < T > ( T disposable ) where T : IDisposable
485
485
{
486
- handlesToCleanup . Push ( handleToCleanup ) ;
486
+ toCleanup . Push ( disposable ) ;
487
+ return disposable ;
487
488
}
488
489
489
490
/// <summary>
0 commit comments