mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Fix leaks caused by http body not close
This commit is contained in:
parent
ebf9e11af2
commit
f93a7d22d3
2 changed files with 6 additions and 2 deletions
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,8 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
|
||||||
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…
Reference in a new issue