Skip to content

Commit

Permalink
Fix resource leak in Nest source due to lack of closing HTTP response…
Browse files Browse the repository at this point in the history
… bodies
  • Loading branch information
cthach committed Aug 6, 2024
1 parent bd88695 commit 66de2f9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/nest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 66de2f9

Please sign in to comment.