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 <mattn.jp@gmail.com>
This commit is contained in:
mattn
2026-05-23 13:50:03 +00:00
committed by GitHub
parent deb1e5b38a
commit 0c489f4ae2

View File

@@ -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()