Skip to content

Commit

Permalink
Merge pull request #1297 from cthach/fix-nest-extend-stream
Browse files Browse the repository at this point in the history
fix(nest): Resource leak due to lack of closing HTTP response bodies
  • Loading branch information
AlexxIT authored Aug 7, 2024
2 parents bd88695 + 66de2f9 commit afc8f4f
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 afc8f4f

Please sign in to comment.