From 190ac977be1256cc29da10b9d62c18a6dce927b3 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Mon, 5 Jun 2023 18:43:04 +0300 Subject: [PATCH] Fix closing file in writeJson and writeSarif (#1187) --- report/json.go | 2 ++ report/sarif.go | 1 + 2 files changed, 3 insertions(+) diff --git a/report/json.go b/report/json.go index 424cb9c2..3a85312c 100644 --- a/report/json.go +++ b/report/json.go @@ -9,6 +9,8 @@ func writeJson(findings []Finding, w io.WriteCloser) error { if len(findings) == 0 { findings = []Finding{} } + defer w.Close() + encoder := json.NewEncoder(w) encoder.SetIndent("", " ") return encoder.Encode(findings) diff --git a/report/sarif.go b/report/sarif.go index 4cf345cd..09719e49 100644 --- a/report/sarif.go +++ b/report/sarif.go @@ -14,6 +14,7 @@ func writeSarif(cfg config.Config, findings []Finding, w io.WriteCloser) error { Version: "2.1.0", Runs: getRuns(cfg, findings), } + defer w.Close() encoder := json.NewEncoder(w) encoder.SetIndent("", " ")