1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Merge pull request #629 from gocsaf/body-close

Avoid memory leak
This commit is contained in:
JanHoefelmeyer 2025-03-25 08:20:22 +01:00 committed by GitHub
commit a05ba731dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -781,11 +781,11 @@ func loadSignature(client util.Client, p string) (*crypto.PGPSignature, []byte,
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, nil, fmt.Errorf( return nil, nil, fmt.Errorf(
"fetching signature from '%s' failed: %s (%d)", p, resp.Status, resp.StatusCode) "fetching signature from '%s' failed: %s (%d)", p, resp.Status, resp.StatusCode)
} }
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -846,11 +846,11 @@ func loadHash(client util.Client, p string) ([]byte, []byte, error) {
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, nil, fmt.Errorf( return nil, nil, fmt.Errorf(
"fetching hash from '%s' failed: %s (%d)", p, resp.Status, resp.StatusCode) "fetching hash from '%s' failed: %s (%d)", p, resp.Status, resp.StatusCode)
} }
defer resp.Body.Close()
var data bytes.Buffer var data bytes.Buffer
tee := io.TeeReader(resp.Body, &data) tee := io.TeeReader(resp.Body, &data)
hash, err := util.HashFromReader(tee) hash, err := util.HashFromReader(tee)