Skip to content

Commit e2e81c8

Browse files
stasos24sosipov
and
sosipov
authoredNov 29, 2023
Fix file handler leak (#1309)
Co-authored-by: sosipov <sosipov@rvision.ru>
1 parent 3b2a2a7 commit e2e81c8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎reporters/json_report.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func GenerateJSONReport(report types.Report, destination string) error {
1818
if err != nil {
1919
return err
2020
}
21+
defer f.Close()
2122
enc := json.NewEncoder(f)
2223
enc.SetIndent("", " ")
2324
err = enc.Encode([]types.Report{
@@ -26,7 +27,7 @@ func GenerateJSONReport(report types.Report, destination string) error {
2627
if err != nil {
2728
return err
2829
}
29-
return f.Close()
30+
return nil
3031
}
3132

3233
// MergeJSONReports produces a single JSON-formatted report at the passed in destination by merging the JSON-formatted reports provided in sources
@@ -57,11 +58,12 @@ func MergeAndCleanupJSONReports(sources []string, destination string) ([]string,
5758
if err != nil {
5859
return messages, err
5960
}
61+
defer f.Close()
6062
enc := json.NewEncoder(f)
6163
enc.SetIndent("", " ")
6264
err = enc.Encode(allReports)
6365
if err != nil {
6466
return messages, err
6567
}
66-
return messages, f.Close()
68+
return messages, nil
6769
}

0 commit comments

Comments
 (0)