mirror of
https://github.com/rancher/norman.git
synced 2025-09-01 07:08:59 +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:
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -216,7 +217,9 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func(closer io.Closer) {
|
||||||
|
closer.Close()
|
||||||
|
}(resp.Body)
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return result, NewAPIError(resp, opts.URL)
|
return result, NewAPIError(resp, opts.URL)
|
||||||
@@ -242,7 +245,9 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func(closer io.Closer) {
|
||||||
|
closer.Close()
|
||||||
|
}(resp.Body)
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return result, NewAPIError(resp, schemasURLs)
|
return result, NewAPIError(resp, schemasURLs)
|
||||||
|
Reference in New Issue
Block a user