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

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Shiming Zhang 2024-03-12 19:12:37 +08:00 committed by GitHub
parent 89cefe240f
commit 99bbbc0277
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -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
} }

View File

@ -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,