From a652659429850150c8447cf759e478f37529a84f Mon Sep 17 00:00:00 2001 From: "Jason T. Greene" Date: Tue, 19 Jul 2022 14:06:47 -0500 Subject: Fix potential leak on mid-stream read error Signed-off-by: Jason T. Greene --- pkg/machine/fedora.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkg/machine') diff --git a/pkg/machine/fedora.go b/pkg/machine/fedora.go index 7ac4692e3..497265269 100644 --- a/pkg/machine/fedora.go +++ b/pkg/machine/fedora.go @@ -105,11 +105,11 @@ func getFedoraDownload(releaseURL string) (*url.URL, string, int64, error) { return nil, "", -1, fmt.Errorf("get request failed: %s: %w", verURL.String(), err) } + defer resp.Body.Close() bytes, err := io.ReadAll(&io.LimitedReader{R: resp.Body, N: 1024}) if err != nil { return nil, "", -1, fmt.Errorf("failed reading: %s: %w", verURL.String(), err) } - _ = resp.Body.Close() return downloadURL, strings.TrimSpace(string(bytes)), contentLen, nil } -- cgit v1.2.3-54-g00ecf