Skip to content

Commit

Permalink
Merge pull request #1173 from iguanesolutions/revoke_leak
Browse files Browse the repository at this point in the history
revoke: fix connection leak
  • Loading branch information
nickysemenza committed Feb 9, 2021
2 parents 9f7129a + f247e5b commit 6eb1640
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions revoke/revoke.go
Expand Up @@ -105,16 +105,17 @@ func fetchCRL(url string) (*pkix.CertificateList, error) {
resp, err := HTTPClient.Get(url)
if err != nil {
return nil, err
} else if resp.StatusCode >= 300 {
}
defer resp.Body.Close()

if resp.StatusCode >= 300 {
return nil, errors.New("failed to retrieve CRL")
}

body, err := crlRead(resp.Body)
if err != nil {
return nil, err
}
resp.Body.Close()

return x509.ParseCRL(body)
}

Expand Down Expand Up @@ -212,12 +213,12 @@ func fetchRemote(url string) (*x509.Certificate, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

in, err := remoteRead(resp.Body)
if err != nil {
return nil, err
}
resp.Body.Close()

p, _ := pem.Decode(in)
if p != nil {
Expand Down Expand Up @@ -290,6 +291,7 @@ func sendOCSPRequest(server string, req []byte, leaf, issuer *x509.Certificate)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, errors.New("failed to retrieve OSCP")
Expand All @@ -299,7 +301,6 @@ func sendOCSPRequest(server string, req []byte, leaf, issuer *x509.Certificate)
if err != nil {
return nil, err
}
resp.Body.Close()

switch {
case bytes.Equal(body, ocsp.UnauthorizedErrorResponse):
Expand Down

0 comments on commit 6eb1640

Please sign in to comment.