Skip to content

Commit a05ba73

Browse files
Merge pull request gocsaf#629 from gocsaf/body-close
Avoid memory leak
2 parents 0848143 + 2c5ef1f commit a05ba73

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cmd/csaf_downloader/downloader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,11 @@ func loadSignature(client util.Client, p string) (*crypto.PGPSignature, []byte,
781781
if err != nil {
782782
return nil, nil, err
783783
}
784+
defer resp.Body.Close()
784785
if resp.StatusCode != http.StatusOK {
785786
return nil, nil, fmt.Errorf(
786787
"fetching signature from '%s' failed: %s (%d)", p, resp.Status, resp.StatusCode)
787788
}
788-
defer resp.Body.Close()
789789
data, err := io.ReadAll(resp.Body)
790790
if err != nil {
791791
return nil, nil, err
@@ -846,11 +846,11 @@ func loadHash(client util.Client, p string) ([]byte, []byte, error) {
846846
if err != nil {
847847
return nil, nil, err
848848
}
849+
defer resp.Body.Close()
849850
if resp.StatusCode != http.StatusOK {
850851
return nil, nil, fmt.Errorf(
851852
"fetching hash from '%s' failed: %s (%d)", p, resp.Status, resp.StatusCode)
852853
}
853-
defer resp.Body.Close()
854854
var data bytes.Buffer
855855
tee := io.TeeReader(resp.Body, &data)
856856
hash, err := util.HashFromReader(tee)

0 commit comments

Comments
 (0)