Skip to content

Commit

Permalink
Close the HTTP response body from oracle DB
Browse files Browse the repository at this point in the history
To honour the requirement in the documentation of the `Do()` method of
Golang's standard HTTP client, if the response body is not nil, always
fully read it and then close it.
  • Loading branch information
dartdart26 committed Apr 12, 2023
1 parent 64bc5ba commit 963c9ad
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"os"
Expand Down Expand Up @@ -1355,14 +1355,12 @@ func verifyZkProof(input []byte) []byte {
if err != nil {
continue
}
// The ZKPoK service returns 406 if the proof is incorrect.
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if resp.StatusCode == 406 {
// The ZKPoK service returns 406 if the proof is incorrect.
return nil
} else if resp.StatusCode != 200 {
continue
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
} else if resp.StatusCode != 200 || err != nil {
continue
}
return body
Expand Down Expand Up @@ -1493,6 +1491,8 @@ func putRequire(ct *tfheCiphertext) bool {
if err != nil {
continue
}
defer resp.Body.Close()
io.ReadAll(resp.Body)
if resp.StatusCode != 200 {
continue
}
Expand All @@ -1516,11 +1516,9 @@ func getRequire(ct *tfheCiphertext) bool {
if err != nil {
continue
}
if resp.StatusCode != 200 {
continue
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if resp.StatusCode != 200 || err != nil {
continue
}
msg := requireMessage{}
Expand Down

0 comments on commit 963c9ad

Please sign in to comment.