Skip to content

Commit

Permalink
fix: close response Body when the returned error is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
jlikeme committed Apr 24, 2022
1 parent 8f104b7 commit 0379d1c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/pkg/vault/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,14 @@ func (c *Client) getAllKeys(subPath string) (map[string]string, error) {
if err != nil {
return nil, err
}
defer func() {
_ = resp.Body.Close()
}()

if resp.StatusCode < 200 || resp.StatusCode > 299 {
return nil, pkg.NewErrSecretStore(fmt.Sprintf("Received a '%d' response from the secret store", resp.StatusCode))
}

defer func() {
_ = resp.Body.Close()
}()

var result map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
Expand Down Expand Up @@ -440,9 +439,7 @@ func (c *Client) store(subPath string, secrets map[string]string) error {
return err
}
defer func() {
if resp.Body != nil {
_ = resp.Body.Close()
}
_ = resp.Body.Close()
}()

if resp.StatusCode < 200 || resp.StatusCode > 299 {
Expand Down

0 comments on commit 0379d1c

Please sign in to comment.