diff --git a/lib/discover/global.go b/lib/discover/global.go index be70e1775..c944f0a2c 100644 --- a/lib/discover/global.go +++ b/lib/discover/global.go @@ -407,6 +407,7 @@ func (c *idCheckingHTTPClient) Get(ctx context.Context, url string) (*http.Respo return nil, err } if err := c.check(resp); err != nil { + resp.Body.Close() return nil, err } @@ -419,6 +420,7 @@ func (c *idCheckingHTTPClient) Post(ctx context.Context, url, ctype string, data return nil, err } if err := c.check(resp); err != nil { + resp.Body.Close() return nil, err } diff --git a/lib/upnp/upnp.go b/lib/upnp/upnp.go index 800218694..854bc7bf3 100644 --- a/lib/upnp/upnp.go +++ b/lib/upnp/upnp.go @@ -607,6 +607,7 @@ func soapRequestWithIP(ctx context.Context, url, service, function, message stri l.Debugln("SOAP do:", err) return resp, err } + defer r.Body.Close() resp, err = io.ReadAll(r.Body) if err != nil { @@ -616,8 +617,6 @@ func soapRequestWithIP(ctx context.Context, url, service, function, message stri l.Debugf("SOAP Response: %s\n\n%s\n\n", r.Status, resp) - r.Body.Close() - if r.StatusCode >= 400 { return resp, errors.New(function + ": " + r.Status) }