Skip to content

Commit 37cc5cf

Browse files
committed
Merge pull request #12 from alcortesm/hotfix-close-packfile
missing call to Close on Fetch return value (ReadCloser)
2 parents cebec78 + 6d19be9 commit 37cc5cf

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

common_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func Test(t *testing.T) { TestingT(t) }
1515

1616
type MockGitUploadPackService struct {
1717
Auth common.AuthMethod
18+
RC io.ReadCloser
1819
}
1920

2021
func (s *MockGitUploadPackService) Connect(url common.Endpoint) error {
@@ -40,8 +41,9 @@ func (s *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
4041
}
4142

4243
func (s *MockGitUploadPackService) Fetch(*common.GitUploadPackRequest) (io.ReadCloser, error) {
43-
r, _ := os.Open("formats/packfile/fixtures/git-fixture.ref-delta")
44-
return r, nil
44+
var err error
45+
s.RC, err = os.Open("formats/packfile/fixtures/git-fixture.ref-delta")
46+
return s.RC, err
4547
}
4648

4749
var fixtureRepos = [...]struct {

repository.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewPlainRepository() *Repository {
5353
}
5454
}
5555

56-
func (r *Repository) Pull(remoteName, branch string) error {
56+
func (r *Repository) Pull(remoteName, branch string) (err error) {
5757
remote, ok := r.Remotes[remoteName]
5858
if !ok {
5959
return fmt.Errorf("unable to find remote %q", remoteName)
@@ -75,6 +75,9 @@ func (r *Repository) Pull(remoteName, branch string) error {
7575
if err != nil {
7676
return err
7777
}
78+
defer func() {
79+
err = reader.Close()
80+
}()
7881

7982
pr := packfile.NewReader(reader)
8083
if _, err = pr.Read(r.Storage); err != nil {

repository_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ func (s *SuiteRepository) TestPull(c *C) {
3131

3232
c.Assert(err, IsNil)
3333
c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)
34+
35+
mock, ok := (r.Remotes["origin"].upSrv).(*MockGitUploadPackService)
36+
c.Assert(ok, Equals, true)
37+
err = mock.RC.Close()
38+
c.Assert(err, Not(IsNil), Commentf("pull leaks an open fd from the fetch"))
3439
}
3540

3641
func (s *SuiteRepository) TestCommit(c *C) {

0 commit comments

Comments
 (0)