Skip to content

Commit 3fd9cb2

Browse files
committed
Close file after write
1 parent fc9ccc3 commit 3fd9cb2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/cli/cli.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func Marshal(testResults parser.Result) ([]byte, error) {
196196
// WriteToFile saves data to given file
197197
func WriteToFile(data []byte, path string) (string, error) {
198198
file, err := os.Create(path) // #nosec
199+
defer file.Close()
199200

200201
if err != nil {
201202
logger.Error("Opening file %s: %v", path, err)
@@ -206,7 +207,8 @@ func WriteToFile(data []byte, path string) (string, error) {
206207

207208
// WriteToTmpFile saves data to temporary file
208209
func WriteToTmpFile(data []byte) (string, error) {
209-
file, err := ioutil.TempFile("", "test-results")
210+
file, err := os.CreateTemp("", "test-results")
211+
defer file.Close()
210212

211213
if err != nil {
212214
logger.Error("Opening file %s: %v", file.Name(), err)

0 commit comments

Comments
 (0)