Fix: nil pointer dereference

This commit is contained in:
kayos@tcp.direct 2022-09-30 13:18:36 -07:00
parent b5f8043af2
commit 6889e618e7
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
2 changed files with 4 additions and 1 deletions

View File

@ -35,6 +35,9 @@ func ParseArgs() {
// CloseBody is crude error handling for any potential errors closing the response body.
func CloseBody(res *http.Response) {
if res.Body == nil || res == nil {
return
}
err := res.Body.Close()
if err != nil {
println("WARN: ProxyGonanza failed to close body for request to ",

View File

@ -98,10 +98,10 @@ func getMyIP() (final net.IP, err error) {
}
var res *http.Response
res, err = http.DefaultClient.Get(endpoint)
defer internal.CloseBody(res)
if err != nil {
return
}
defer internal.CloseBody(res)
var body []byte
body, err = ioutil.ReadAll(res.Body)
if err != nil {