From 2c7bdb9fd14f8c6e106da25a16fcdfbe3220134b Mon Sep 17 00:00:00 2001 From: Karen <8099322@qq.com> Date: Tue, 12 Nov 2024 09:47:22 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20fix:=20Close=20File=20After=20Sa?= =?UTF-8?q?veFileToStorage=20(#3197)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: close file after opening in SaveFileToStorage to prevent resource leaks * ♻️ refactor: simplify file close logic * Update ctx.go --------- Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> --- ctx.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ctx.go b/ctx.go index 1bbf2ba130..fcf5c138da 100644 --- a/ctx.go +++ b/ctx.go @@ -1470,6 +1470,7 @@ func (*DefaultCtx) SaveFileToStorage(fileheader *multipart.FileHeader, path stri if err != nil { return fmt.Errorf("failed to open: %w", err) } + defer file.Close() //nolint:errcheck // not needed content, err := io.ReadAll(file) if err != nil {