From e1b0582859e9d5c81c3aa22c2aa3d09ee4381451 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Wed, 25 Aug 2021 18:43:01 +0200 Subject: [PATCH] fsOpenFile: Close on error (#13064) Close files on error. --- cmd/fs-v1-helpers.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/fs-v1-helpers.go b/cmd/fs-v1-helpers.go index fc8551e68..2e3413273 100644 --- a/cmd/fs-v1-helpers.go +++ b/cmd/fs-v1-helpers.go @@ -268,6 +268,7 @@ func fsOpenFile(ctx context.Context, readPath string, offset int64) (io.ReadClos // Stat to get the size of the file at path. st, err := fr.Stat() if err != nil { + fr.Close() err = osErrToFileErr(err) if err != errFileNotFound { logger.LogIf(ctx, err) @@ -277,6 +278,7 @@ func fsOpenFile(ctx context.Context, readPath string, offset int64) (io.ReadClos // Verify if its not a regular file, since subsequent Seek is undefined. if !st.Mode().IsRegular() { + fr.Close() return nil, 0, errIsNotRegular } @@ -284,6 +286,7 @@ func fsOpenFile(ctx context.Context, readPath string, offset int64) (io.ReadClos if offset > 0 { _, err = fr.Seek(offset, io.SeekStart) if err != nil { + fr.Close() logger.LogIf(ctx, err) return nil, 0, err }