Skip to content

Commit

Permalink
Fix G307 warning: Deferring unsafe method "Close" on type "*os.File" (#…
Browse files Browse the repository at this point in the history
…1154)

* fix: check potential error from file.Close

* fix(detect): use existing logger
  • Loading branch information
rgmz committed Apr 19, 2023
1 parent bd8b145 commit 81cf308
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion detect/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
return err
}

defer file.Close()
// https://github.com/securego/gosec/issues/512
defer func() {
if err := file.Close(); err != nil {
log.Warn().Msgf("Error closing .gitleaksignore file: %s\n", err)
}
}()
scanner := bufio.NewScanner(file)

for scanner.Scan() {
Expand Down

0 comments on commit 81cf308

Please sign in to comment.