Skip to content

Commit db0b052

Browse files
committed
Fix memory leak
1 parent ac6b995 commit db0b052

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

LibGit2Sharp/Repository.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,21 @@ public static string Clone(string sourceUrl, string workdirPath,
556556
Bare = options.IsBare ? 1 : 0,
557557
CheckoutOpts = gitCheckoutOptions,
558558
RemoteCallbacks = gitRemoteCallbacks,
559-
CheckoutBranch = StrictUtf8Marshaler.FromManaged(options.BranchName)
560559
};
561560

562-
FilePath repoPath;
563-
using (RepositorySafeHandle repo = Proxy.git_clone(sourceUrl, workdirPath, ref cloneOpts))
561+
try
564562
{
565-
repoPath = Proxy.git_repository_path(repo);
566-
}
563+
cloneOpts.CheckoutBranch = StrictUtf8Marshaler.FromManaged(options.BranchName);
567564

568-
return repoPath.Native;
565+
using (RepositorySafeHandle repo = Proxy.git_clone(sourceUrl, workdirPath, ref cloneOpts))
566+
{
567+
return Proxy.git_repository_path(repo).Native;
568+
}
569+
}
570+
finally
571+
{
572+
EncodingMarshaler.Cleanup(cloneOpts.CheckoutBranch);
573+
}
569574
}
570575
}
571576

0 commit comments

Comments
 (0)