Skip to content

Commit b2c1583

Browse files
committed
commit: fix possible goroutine leak
1 parent f4026b5 commit b2c1583

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

commit.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,7 @@ func NewCommitFileStatus() *CommitFileStatus {
271271
// GetCommitFileStatus returns file status of commit in given repository.
272272
func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error) {
273273
stdout, w := io.Pipe()
274-
defer stdout.Close()
275-
276-
stderr := new(bytes.Buffer)
277-
274+
done := make(chan struct{})
278275
fileStatus := NewCommitFileStatus()
279276
go func() {
280277
scanner := bufio.NewScanner(stdout)
@@ -293,12 +290,17 @@ func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error) {
293290
fileStatus.Modified = append(fileStatus.Modified, fields[1])
294291
}
295292
}
293+
done <- struct{}{}
296294
}()
297295

298-
if err := NewCommand("log", "-1", "--name-status", "--pretty=format:''", commitID).RunInDirPipeline(repoPath, w, stderr); err != nil {
296+
stderr := new(bytes.Buffer)
297+
err := NewCommand("log", "-1", "--name-status", "--pretty=format:''", commitID).RunInDirPipeline(repoPath, w, stderr)
298+
w.Close() // Close writer to exit parsing goroutine
299+
if err != nil {
299300
return nil, concatenateError(err, stderr.String())
300301
}
301302

303+
<-done
302304
return fileStatus, nil
303305
}
304306

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.5.1"
13+
const _VERSION = "0.5.2"
1414

1515
func Version() string {
1616
return _VERSION

0 commit comments

Comments
 (0)