Skip to content

Commit

Permalink
Fix file handler leak (#1309)
Browse files Browse the repository at this point in the history
Co-authored-by: sosipov <sosipov@rvision.ru>
  • Loading branch information
stasos24 and sosipov committed Nov 29, 2023
1 parent 3b2a2a7 commit e2e81c8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions reporters/json_report.go
Expand Up @@ -18,6 +18,7 @@ func GenerateJSONReport(report types.Report, destination string) error {
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
err = enc.Encode([]types.Report{
Expand All @@ -26,7 +27,7 @@ func GenerateJSONReport(report types.Report, destination string) error {
if err != nil {
return err
}
return f.Close()
return nil
}

// MergeJSONReports produces a single JSON-formatted report at the passed in destination by merging the JSON-formatted reports provided in sources
Expand Down Expand Up @@ -57,11 +58,12 @@ func MergeAndCleanupJSONReports(sources []string, destination string) ([]string,
if err != nil {
return messages, err
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
err = enc.Encode(allReports)
if err != nil {
return messages, err
}
return messages, f.Close()
return messages, nil
}

0 comments on commit e2e81c8

Please sign in to comment.