Skip to content

Commit

Permalink
retrieveDeviceAuth: Call r.Body.Close()
Browse files Browse the repository at this point in the history
Close the response body after reading it in the DeviceAuth logic.

The retrieveDeviceAuth function did not close the response body.
However, the net/http documentation states that one is expected to close
the response body after one sends an HTTP request and reads the response
body.  In addition, the doTokenRoundTrip function *does* call
r.Body.Close().  (Some other functions use a client with a custom
Transport that automatically closes the body, but that is not the case
for retrieveDeviceAuth or doTokenRoundTrip.)

Follow-up to commit e3fb0fb.

* deviceauth.go (retrieveDeviceAuth): Call r.Body.Close() after reading
r.Body.
  • Loading branch information
Miciah committed Nov 4, 2024
1 parent 22134a4 commit ffeca96
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions deviceauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func retrieveDeviceAuth(ctx context.Context, c *Config, v url.Values) (*DeviceAu
}

body, err := io.ReadAll(io.LimitReader(r.Body, 1<<20))
r.Body.Close()
if err != nil {
return nil, fmt.Errorf("oauth2: cannot auth device: %v", err)
}
Expand Down

0 comments on commit ffeca96

Please sign in to comment.