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 Jan 24, 2025
1 parent 22134a4 commit 8499b41
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 @@ -111,6 +111,7 @@ func retrieveDeviceAuth(ctx context.Context, c *Config, v url.Values) (*DeviceAu
return nil, err
}

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

0 comments on commit 8499b41

Please sign in to comment.