From 0c489f4ae2cbfd7faaa60f38e8812caa481939ae Mon Sep 17 00:00:00 2001 From: mattn Date: Sat, 23 May 2026 13:50:03 +0000 Subject: [PATCH] fix(stcrashreceiver): close source loader responses on errors (#10704) Fix a response body leak in `githubSourceCodeLoader.Load` where the body was not closed when the HTTP status was non-200. Signed-off-by: Yasuhiro Matsumoto --- cmd/infra/stcrashreceiver/sourcecodeloader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/infra/stcrashreceiver/sourcecodeloader.go b/cmd/infra/stcrashreceiver/sourcecodeloader.go index 564981926..03da397e6 100644 --- a/cmd/infra/stcrashreceiver/sourcecodeloader.go +++ b/cmd/infra/stcrashreceiver/sourcecodeloader.go @@ -85,13 +85,13 @@ func (l *githubSourceCodeLoader) Load(filename string, line, context int) ([][]b metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc() return nil, 0 } + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { fmt.Println("Loading source:", resp.Status) metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc() return nil, 0 } data, err := io.ReadAll(resp.Body) - _ = resp.Body.Close() if err != nil { fmt.Println("Loading source:", err.Error()) metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc()