From e0eec944fba5e6b4e3ceb509a7192d902a3586cb Mon Sep 17 00:00:00 2001 From: Havrileck Alexandre Date: Mon, 19 Jun 2023 21:09:47 +0200 Subject: [PATCH] fix(server): Close file on upload and remove all files from form when PUT request is finished --- pkg/s3-proxy/server/server.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/s3-proxy/server/server.go b/pkg/s3-proxy/server/server.go index 2e052af1..20e31e9e 100644 --- a/pkg/s3-proxy/server/server.go +++ b/pkg/s3-proxy/server/server.go @@ -393,6 +393,7 @@ func (svr *Server) generateRouter() (http.Handler, error) { return } + // Parse multipart form err = req.ParseMultipartForm(0) if err != nil { @@ -407,6 +408,11 @@ func (svr *Server) generateRouter() (http.Handler, error) { return } + // Defer close file + defer file.Close() + // Defer remove all form + defer req.MultipartForm.RemoveAll() //nolint: errcheck // Ignored + // Create input for put request inp := &bucket.PutInput{ RequestPath: requestPath,