Skip to content

Commit afc8f4f

Browse files
authored
Merge pull request #1297 from cthach/fix-nest-extend-stream
fix(nest): Resource leak due to lack of closing HTTP response bodies
2 parents bd88695 + 66de2f9 commit afc8f4f

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

pkg/nest/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ func NewAPI(clientID, clientSecret, refreshToken string) (*API, error) {
5353
if err != nil {
5454
return nil, err
5555
}
56+
defer res.Body.Close()
57+
5658
if res.StatusCode != 200 {
5759
return nil, errors.New("nest: wrong status: " + res.Status)
5860
}
@@ -92,6 +94,7 @@ func (a *API) GetDevices(projectID string) (map[string]string, error) {
9294
if err != nil {
9395
return nil, err
9496
}
97+
defer res.Body.Close()
9598

9699
if res.StatusCode != 200 {
97100
return nil, errors.New("nest: wrong status: " + res.Status)
@@ -157,6 +160,7 @@ func (a *API) ExchangeSDP(projectID, deviceID, offer string) (string, error) {
157160
if err != nil {
158161
return "", err
159162
}
163+
defer res.Body.Close()
160164

161165
if res.StatusCode != 200 {
162166
return "", errors.New("nest: wrong status: " + res.Status)
@@ -211,6 +215,7 @@ func (a *API) ExtendStream() error {
211215
if err != nil {
212216
return err
213217
}
218+
defer res.Body.Close()
214219

215220
if res.StatusCode != 200 {
216221
return errors.New("nest: wrong status: " + res.Status)

0 commit comments

Comments
 (0)