8000 Stop leaking rebase operation handles. · markcapaldi/libgit2sharp@3cb78c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3cb78c2

Browse files
committed
Stop leaking rebase operation handles.
1 parent 83ced0b commit 3cb78c2

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

LibGit2Sharp/RebaseOperation.cs

Lines changed: 21 additions & 12 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, opt 8000 ions);
101100
return rebaseResult;
102101
}
103102
finally
@@ -140,16 +139,26 @@ public virtual RebaseStepInfo CurrentStepInfo
140139
{
141140
get
142141
{
143-
var rebase = Proxy.git_rebase_open(repository.Handle);
144-
int currentStepIndex = Proxy.git_rebase_operation_current(rebase);
145-
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebase);
146-
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebase, currentStepIndex);
147-
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
148-
gitRebasestepInfo.id,
149-
LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo.exec),
150-
currentStepIndex,
151-
totalStepCount);
152-
return stepInfo;
142+
RebaseSafeHandle rebaseHandle = null;
143+
144+
try
145+
{
146+
rebaseHandle = Proxy.git_rebase_open(repository.Handle);
147+
int currentStepIndex = Proxy.git_rebase_operation_current(rebaseHandle);
148+
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseHandle);
149+
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebaseHandle, currentStepIndex);
150+
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
151+
gitRebasestepInfo.id,
152+
LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo.exec),
153+
currentStepIndex,
154+
totalStepCount);
155+
return stepInfo;
156+
}
157+
finally
158+
{
159+
rebaseHandle.SafeDispose();
160+
rebaseHandle = null;
161+
}
153162
}
154163
}
155164
}

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
@@ -1105,6 +1105,8 @@ public RebaseResult Rebase(Branch branch, Branch upstream, Branch onto, Signatur
11051105
GitAnnotatedCommitHandle annotatedUpstreamRefPtrCommitHandle = null;
11061106
GitAnnotatedCommitHandle annotatedOntoRefPtrCommitHandle = null;
11071107

1108+
RebaseSafeHandle rebaseOperationHandle = null;
1109+
11081110
try
11091111
{
11101112
branchRefPtr = (branch == null) ?
@@ -1134,15 +1136,13 @@ public RebaseResult Rebase(Branch branch, Branch upstream, Branch onto, Signatur
11341136
version = 1,
11351137
};
11361138

1137-
RebaseSafeHandle rebaseOperationHandle = Proxy.git_rebase_init(this.Handle,
1139+
rebaseOperationHandle = Proxy.git_rebase_init(this.Handle,
11381140
annotatedBranchCommitHandle,
11391141
annotatedUpstreamRefPtrCommitHandle,
11401142
annotatedOntoRefPtrCommitHandle,
11411143
null, ref gitRebaseOptions);
11421144

1143-
var rebaseDriver = new RebaseOperationImpl(rebaseOperationHandle, this, committer, options);
1144-
RebaseResult rebaseResult = rebaseDriver.Run();
1145-
1145+
RebaseResult rebaseResult = RebaseOperationImpl.Run(rebaseOperationHandle, this, committer, options);
11461146
return rebaseResult;
11471147
}
11481148
finally
@@ -1160,6 +1160,9 @@ public RebaseResult Rebase(Branch branch, Branch upstream, Branch onto, Signatur
11601160
annotatedUpstreamRefPtrCommitHandle = null;
11611161
annotatedOntoRefPtrCommitHandle.SafeDispose();
11621162
annotatedOntoRefPtrCommitHandle = null;
1163+
1164+
rebaseOperationHandle.SafeDispose();
1165+
rebaseOperationHandle = null;
11631166
}
11641167
}
11651168

0 commit comments

Comments
 (0)
0