Close client connection when done.

This will take care of cleaning all the lingering connections that would have been left open which would eventually trigger a too many files error or an OOM.
This commit is contained in:
Paulo E. Castro 2022-11-25 20:24:47 +00:00
parent 84463e2815
commit aa09e7c660
No known key found for this signature in database
GPG Key ID: 732E6D35F6EC7D88

View File

@ -201,6 +201,7 @@ func (c *Client) getStatistics() (*Stats, error) {
return nil, fmt.Errorf("an error has occured during retrieving PI-Hole statistics: %w", err) return nil, fmt.Errorf("an error has occured during retrieving PI-Hole statistics: %w", err)
} }
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read PI-Hole statistics HTTP response: %w", err) return nil, fmt.Errorf("unable to read PI-Hole statistics HTTP response: %w", err)