From 66de2f91b655b99bbb86c08f9037737eb528bb41 Mon Sep 17 00:00:00 2001 From: Chris Thach <12981621+cthach@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:25:55 +0000 Subject: [PATCH] Fix resource leak in Nest source due to lack of closing HTTP response bodies --- pkg/nest/api.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/nest/api.go b/pkg/nest/api.go index 5e0d3407..9d187054 100644 --- a/pkg/nest/api.go +++ b/pkg/nest/api.go @@ -53,6 +53,8 @@ func NewAPI(clientID, clientSecret, refreshToken string) (*API, error) { if err != nil { return nil, err } + defer res.Body.Close() + if res.StatusCode != 200 { return nil, errors.New("nest: wrong status: " + res.Status) } @@ -92,6 +94,7 @@ func (a *API) GetDevices(projectID string) (map[string]string, error) { if err != nil { return nil, err } + defer res.Body.Close() if res.StatusCode != 200 { return nil, errors.New("nest: wrong status: " + res.Status) @@ -157,6 +160,7 @@ func (a *API) ExchangeSDP(projectID, deviceID, offer string) (string, error) { if err != nil { return "", err } + defer res.Body.Close() if res.StatusCode != 200 { return "", errors.New("nest: wrong status: " + res.Status) @@ -211,6 +215,7 @@ func (a *API) ExtendStream() error { if err != nil { return err } + defer res.Body.Close() if res.StatusCode != 200 { return errors.New("nest: wrong status: " + res.Status)