Fix resource leak in Nest source due to lack of closing HTTP response bodies

This commit is contained in:
Chris Thach
2024-08-06 22:25:55 +00:00
parent bd88695e59
commit 66de2f91b6

View File

@@ -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)