Skip to content

Commit 573bddf

Browse files
committed
Stop leaking rebase operation handles.
1 parent 88ab1ed commit 573bddf

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

LibGit2Sharp/RebaseOperation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
9696
options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo, new ObjectId(id)));
9797
}
9898

99-
var rebaseDriver = new RebaseOperationImpl(rebase, repository, committer, options);
100-
RebaseResult rebaseResult = rebaseDriver.Run();
99+
RebaseResult rebaseResult = RebaseOperationImpl.Run(rebase, repository, committer, options);
101100
return rebaseResult;
102101
}
103102
finally

LibGit2Sharp/RebaseOperationImpl.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,25 @@ namespace LibGit2Sharp
99
{
1010
internal class RebaseOperationImpl
1111
{
12-
private RebaseSafeHandle rebaseOperationHandle;
13-
private Repository repository;
14-
private Signature committer;
15-
private RebaseOptions options;
1612

17-
public RebaseOperationImpl(RebaseSafeHandle rebaseOp, Repository repo, Signature committer, RebaseOptions options)
13+
/// <summary>
14+
/// Run a rebase to completion, a conflict, or a requested stop point.
15+
/// </summary>
16+
/// <param name="rebaseOperationHandle">Handle to the rebase operation.</param>
17+
/// <param name="repository">Repository in which rebase operation is being run.</param>
18+
/// <param name="committer">Committer signature to use for the rebased commits.</param>
19+
/// <param name="options">Options controlling rebase behavior.</param>
20+
/// <returns>RebaseResult - describing the result of the rebase operation.</returns>
21+
public static RebaseResult Run(RebaseSafeHandle rebaseOperationHandle,
22+
Repository repository,
23+
Signature committer,
24+
RebaseOptions options)
1825
{
19-
Ensure.ArgumentNotNull(rebaseOp, "rebaseOp");
20-
Ensure.ArgumentNotNull(repo, "repo");
26+
Ensure.ArgumentNotNull(rebaseOperationHandle, "rebaseOperationHandle");
27+
Ensure.ArgumentNotNull(repository, "repository");
2128
Ensure.ArgumentNotNull(committer, "committer");
2229
Ensure.ArgumentNotNull(options, "options");
2330

24-
this.rebaseOperationHandle = rebaseOp;
25-
this.repository = repo;
26-
this.committer = committer;
27-
this.options = options;
28-
}
29-
30-
/// <summary>
31-
/// Run a rebase to completion or conflict.
32-
/// </summary>
33-
/// <returns>true if completed successfully, false if conflicts encountered.</returns>
34-
public RebaseResult Run()
35-
{
3631
GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options);
3732
GitCheckoutOpts gitCheckoutOpts = checkoutOptionsWrapper.Options;
3833
RebaseResult rebaseResult = null;

LibGit2Sharp/Repository.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,8 @@ public RebaseResult Rebase(Branch branch, Branch upstream, Branch onto, Signatur
11121112
GitAnnotatedCommitHandle annotatedUpstreamRefPtrCommitHandle = null;
11131113
GitAnnotatedCommitHandle annotatedOntoRefPtrCommitHandle = null;
11141114

1115+
RebaseSafeHandle rebaseOperationHandle = null;
1116+
11151117
try
11161118
{
11171119
branchRefPtr = (branch == null) ?
@@ -1141,15 +1143,13 @@ public RebaseResult Rebase(Branch branch, Branch upstream, Branch onto, Signatur
11411143
version = 1,
11421144
};
11431145

1144-
RebaseSafeHandle rebaseOperationHandle = Proxy.git_rebase_init(this.Handle,
1146+
rebaseOperationHandle = Proxy.git_rebase_init(this.Handle,
11451147
annotatedBranchCommitHandle,
11461148
annotatedUpstreamRefPtrCommitHandle,
11471149
annotatedOntoRefPtrCommitHandle,
11481150
null, ref gitRebaseOptions);
11491151

1150-
var rebaseDriver = new RebaseOperationImpl(rebaseOperationHandle, this, committer, options);
1151-
RebaseResult rebaseResult = rebaseDriver.Run();
1152-
1152+
RebaseResult rebaseResult = RebaseOperationImpl.Run(rebaseOperationHandle, this, committer, options);
11531153
return rebaseResult;
11541154
}
11551155
finally
@@ -1167,6 +1167,9 @@ public RebaseResult Rebase(Branch branch, Branch upstream, Branch onto, Signatur
11671167
annotatedUpstreamRefPtrCommitHandle = null;
11681168
annotatedOntoRefPtrCommitHandle.SafeDispose();
11691169
annotatedOntoRefPtrCommitHandle = null;
1170+
1171+
rebaseOperationHandle.SafeDispose();
1172+
rebaseOperationHandle = null;
11701173
}
11711174
}
11721175

0 commit comments

Comments
 (0)