Skip to content

Commit 3e90e8a

Browse files
committed
move close into the defer
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 32342b3 commit 3e90e8a

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

modules/git/repo_attribute.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ func (c *CheckAttributeReader) Init(ctx context.Context) error {
184184

185185
// Run run cmd
186186
func (c *CheckAttributeReader) Run() error {
187-
defer func() {
188-
_ = c.Close()
189-
}()
190187
stdErr := new(bytes.Buffer)
191188
err := c.cmd.RunWithContext(&RunContext{
192189
Env: c.env,
@@ -196,7 +193,11 @@ func (c *CheckAttributeReader) Run() error {
196193
Stdout: c.stdOut,
197194
Stderr: stdErr,
198195
PipelineFunc: func(_ context.Context, _ context.CancelFunc) error {
199-
close(c.running)
196+
select {
197+
case <-c.running:
198+
default:
199+
close(c.running)
200+
}
200201
return nil
201202
},
202203
})
@@ -243,10 +244,10 @@ func (c *CheckAttributeReader) CheckPath(path string) (rs map[string]string, err
243244

244245
// Close close pip after use
245246
func (c *CheckAttributeReader) Close() error {
247+
c.cancel()
246248
err := c.stdinWriter.Close()
247249
_ = c.stdinReader.Close()
248250
_ = c.stdOut.Close()
249-
c.cancel()
250251
select {
251252
case <-c.running:
252253
default:

modules/git/repo_language_stats_nogogit.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
8888
}
8989
}()
9090
}
91-
defer cancel()
91+
defer func() {
92+
_ = checker.Close()
93+
cancel()
94+
}()
9295
}
9396
}
9497

services/gitdiff/gitdiff.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,6 @@ func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff
14181418
if err != nil && err != ctx.Err() {
14191419
log.Error("Unable to open checker for %s. Error: %v", opts.AfterCommitID, err)
14201420
}
1421-
_ = checker.Close()
14221421
cancel()
14231422
}()
14241423
}

0 commit comments

Comments
 (0)