Make sure to close the body
Change-Id: Idab0ebad1f5f10b0a40a9a6f3663d74a5a9f8e1c
diff --git a/oauth2device.go b/oauth2device.go
index 05869ff..72a719a 100644
--- a/oauth2device.go
+++ b/oauth2device.go
@@ -89,10 +89,11 @@
scopes := strings.Join(config.Scopes, " ")
resp, err := client.PostForm(config.DeviceEndpoint.CodeURL,
url.Values{"client_id": {config.ClientID}, "scope": {scopes}})
-
if err != nil {
return nil, err
}
+ defer resp.Body.Close()
+
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(
"request for device code authorisation returned status %v (%v)",
@@ -125,6 +126,8 @@
if err != nil {
return nil, err
}
+ defer resp.Body.Close()
+
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("HTTP error %v (%v) when polling for OAuth token",
resp.StatusCode, http.StatusText(resp.StatusCode))