libgit2: dispose git2go objects when error != nil
getBlankRepoAndRemote's callers are responsible for the disposal of the returned objects. However, the caller does not expect to need to dispose objects when err != nil, which may result to memory leaks. Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
This commit is contained in:
parent
54e07d8783
commit
44e166e576
|
@ -428,12 +428,15 @@ func getBlankRepoAndRemote(ctx context.Context, path, url string, opts *git.Auth
|
|||
|
||||
remote, err := repo.Remotes.Create("origin", url)
|
||||
if err != nil {
|
||||
repo.Free()
|
||||
return nil, nil, fmt.Errorf("unable to create remote for '%s': %w", managed.EffectiveURL(url), gitutil.LibGit2Error(err))
|
||||
}
|
||||
|
||||
callBacks := RemoteCallbacks(ctx, opts)
|
||||
err = remote.ConnectFetch(&callBacks, &git2go.ProxyOptions{Type: git2go.ProxyTypeAuto}, nil)
|
||||
if err != nil {
|
||||
remote.Free()
|
||||
repo.Free()
|
||||
return nil, nil, fmt.Errorf("unable to fetch-connect to remote '%s': %w", managed.EffectiveURL(url), gitutil.LibGit2Error(err))
|
||||
}
|
||||
return repo, remote, nil
|
||||
|
|
Loading…
Reference in New Issue