NetClientUtils: Avoid using defer in a for loop, this causes resource leaks.

This commit is contained in:
kayos@tcp.direct 2023-02-16 02:09:58 -08:00
parent 92dbfa52a5
commit a15650d3e0
No known key found for this signature in database
GPG key ID: 4B841471B4BEE979

View file

@ -166,13 +166,16 @@ func GetPublicIP(api string) (string, error) {
if err != nil {
continue
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
var bodyBytes []byte
bodyBytes, err = io.ReadAll(resp.Body)
if err != nil {
if resp.Body != nil {
_ = resp.Body.Close()
}
continue
}
_ = resp.Body.Close()
endpoint = string(bodyBytes)
break
}