From bf277e197f863545694e238778c282cf71e47a38 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 19 Jul 2023 14:19:04 +0300 Subject: [PATCH] Always close response body in uploads --- libgm/media.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libgm/media.go b/libgm/media.go index d5c5baa..7b347a1 100644 --- a/libgm/media.go +++ b/libgm/media.go @@ -154,14 +154,13 @@ func (c *Client) FinalizeUploadMedia(upload *StartGoogleUpload) (*MediaUpload, e if resErr != nil { panic(resErr) } + defer res.Body.Close() statusCode := res.StatusCode if statusCode != 200 { return nil, errFinalizeUploadMedia } - defer res.Body.Close() - rHeaders := res.Header googleResponse, err3 := io.ReadAll(base64.NewDecoder(base64.StdEncoding, res.Body)) if err3 != nil { @@ -202,6 +201,7 @@ func (c *Client) StartUploadMedia(encryptedImageBytes []byte, mime string) (*Sta if resErr != nil { panic(resErr) } + defer res.Body.Close() statusCode := res.StatusCode if statusCode != 200 {