mirror of
https://github.com/gravitl/netmaker.git
synced 2025-12-16 07:38:17 +08:00
NetClientUtils: Avoid using defer in a for loop, this causes resource leaks.
This commit is contained in:
parent
92dbfa52a5
commit
a15650d3e0
1 changed files with 4 additions and 1 deletions
|
|
@ -166,13 +166,16 @@ func GetPublicIP(api string) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode == http.StatusOK {
|
if resp.StatusCode == http.StatusOK {
|
||||||
var bodyBytes []byte
|
var bodyBytes []byte
|
||||||
bodyBytes, err = io.ReadAll(resp.Body)
|
bodyBytes, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.Body != nil {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
_ = resp.Body.Close()
|
||||||
endpoint = string(bodyBytes)
|
endpoint = string(bodyBytes)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue