yandex: Fix socket leaks

This commit is contained in:
Nick Craig-Wood
2015-12-30 14:30:16 +00:00
parent 82b85431bd
commit 9ade179407
7 changed files with 14 additions and 13 deletions
+2 -2
View File
@@ -8,7 +8,7 @@ import (
)
// PerformDownload does the actual download via unscoped PUT request.
func (c *Client) PerformDownload(url string) (io.ReadCloser, error) {
func (c *Client) PerformDownload(url string) (out io.ReadCloser, err error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
@@ -22,11 +22,11 @@ func (c *Client) PerformDownload(url string) (io.ReadCloser, error) {
}
if resp.StatusCode != 200 {
defer CheckClose(resp.Body, &err)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
defer CheckClose(resp.Body, &err)
return nil, fmt.Errorf("download error [%d]: %s", resp.StatusCode, string(body[:]))
}
return resp.Body, err