1
0
mirror of https://github.com/rancher/norman.git synced 2025-08-31 23:02:01 +00:00

ensure resp.Body closed

In the old code, `resp` defined at line 215 will be rewrite at line 241. So that the `resp` after `defer` at both line 219 and 245 will operate the same one. And the other on leaks.
This commit is contained in:
^_^void
2019-03-27 20:34:04 +08:00
committed by GitHub
parent e10534b012
commit f49de2f44d

View File

@@ -7,6 +7,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
@@ -216,7 +217,9 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
if err != nil {
return result, err
}
defer resp.Body.Close()
defer func(closer io.Closer) {
closer.Close()
}(resp.Body)
if resp.StatusCode != 200 {
return result, NewAPIError(resp, opts.URL)
@@ -242,7 +245,9 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
if err != nil {
return result, err
}
defer resp.Body.Close()
defer func(closer io.Closer) {
closer.Close()
}(resp.Body)
if resp.StatusCode != 200 {
return result, NewAPIError(resp, schemasURLs)