internal/build, rpc: add missing HTTP response body Close() calls (#29223)

Co-authored-by: Felix Lange <fjl@twurst.com>
pull/29238/head
Shiming Zhang 8 months ago committed by GitHub
parent 89cefe240f
commit 99bbbc0277
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      internal/build/download.go
  2. 2
      rpc/http.go

@ -84,10 +84,12 @@ func (db *ChecksumDB) DownloadFile(url, dstPath string) error {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return fmt.Errorf("download error: %v", err) return fmt.Errorf("download error: %v", err)
} else if resp.StatusCode != http.StatusOK {
return fmt.Errorf("download error: status %d", resp.StatusCode)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("download error: status %d", resp.StatusCode)
}
if err := os.MkdirAll(filepath.Dir(dstPath), 0755); err != nil { if err := os.MkdirAll(filepath.Dir(dstPath), 0755); err != nil {
return err return err
} }

@ -236,7 +236,7 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
if _, err := buf.ReadFrom(resp.Body); err == nil { if _, err := buf.ReadFrom(resp.Body); err == nil {
body = buf.Bytes() body = buf.Bytes()
} }
resp.Body.Close()
return nil, HTTPError{ return nil, HTTPError{
Status: resp.Status, Status: resp.Status,
StatusCode: resp.StatusCode, StatusCode: resp.StatusCode,

Loading…
Cancel
Save