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:
@@ -85,13 +85,13 @@ func (l *githubSourceCodeLoader) Load(filename string, line, context int) ([][]b
|
|||||||
metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc()
|
metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc()
|
||||||
return nil, 0
|
return nil, 0
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
fmt.Println("Loading source:", resp.Status)
|
fmt.Println("Loading source:", resp.Status)
|
||||||
metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc()
|
metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc()
|
||||||
return nil, 0
|
return nil, 0
|
||||||
}
|
}
|
||||||
data, err := io.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
_ = resp.Body.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Loading source:", err.Error())
|
fmt.Println("Loading source:", err.Error())
|
||||||
metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc()
|
metricSourceCodeLoadsTotal.WithLabelValues("failed").Inc()
|
||||||
|
|||||||
Reference in New Issue
Block a user