Skip to content

Commit 963c9ad

Browse files
committed
Close the HTTP response body from oracle DB
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.
1 parent 64bc5ba commit 963c9ad

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

core/vm/contracts.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"encoding/json"
2626
"errors"
2727
"fmt"
28-
"io/ioutil"
28+
"io"
2929
"math/big"
3030
"net/http"
3131
"os"
@@ -1355,14 +1355,12 @@ func verifyZkProof(input []byte) []byte {
13551355
if err != nil {
13561356
continue
13571357
}
1358-
// The ZKPoK service returns 406 if the proof is incorrect.
1358+
defer resp.Body.Close()
1359+
body, err := io.ReadAll(resp.Body)
13591360
if resp.StatusCode == 406 {
1361+
// The ZKPoK service returns 406 if the proof is incorrect.
13601362
return nil
1361-
} else if resp.StatusCode != 200 {
1362-
continue
1363-
}
1364-
body, err := ioutil.ReadAll(resp.Body)
1365-
if err != nil {
1363+
} else if resp.StatusCode != 200 || err != nil {
13661364
continue
13671365
}
13681366
return body
@@ -1493,6 +1491,8 @@ func putRequire(ct *tfheCiphertext) bool {
14931491
if err != nil {
14941492
continue
14951493
}
1494+
defer resp.Body.Close()
1495+
io.ReadAll(resp.Body)
14961496
if resp.StatusCode != 200 {
14971497
continue
14981498
}
@@ -1516,11 +1516,9 @@ func getRequire(ct *tfheCiphertext) bool {
15161516
if err != nil {
15171517
continue
15181518
}
1519-
if resp.StatusCode != 200 {
1520-
continue
1521-
}
1522-
body, err := ioutil.ReadAll(resp.Body)
1523-
if err != nil {
1519+
defer resp.Body.Close()
1520+
body, err := io.ReadAll(resp.Body)
1521+
if resp.StatusCode != 200 || err != nil {
15241522
continue
15251523
}
15261524
msg := requireMessage{}

0 commit comments

Comments
 (0)