Skip to content

Commit

Permalink
fix: resolve gosec error G307
Browse files Browse the repository at this point in the history
```
G307 (CWE-703): Deferring unsafe method "Close" on type "*os.File"
```

Solution from:
securego/gosec#512
  • Loading branch information
vpayno committed Aug 2, 2022
1 parent 87d8123 commit 854cf06
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/app/quiz/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ func loadData(c config) quizData {
Exit(1, fmt.Sprintf("Failed to open the CSV file: %q\n", c.fileName))
}

defer file.Close()
defer func() {
if err := file.Close(); err != nil {
fmt.Printf("Error closing file: %s\n", err)
}
}()

r := csv.NewReader(file)

Expand Down

0 comments on commit 854cf06

Please sign in to comment.