From dc8bf6b02857f34638a6d0888d05ba470e33b68e Mon Sep 17 00:00:00 2001 From: yanghx Date: Fri, 13 Oct 2023 15:01:23 +0800 Subject: [PATCH] =?UTF-8?q?ReadOrErr=20=E8=AF=BB=E5=8F=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8E=EF=BC=8C=E5=85=B3=E9=97=AD=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fsutil/opread.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fsutil/opread.go b/fsutil/opread.go index 87f17504b..71ed98457 100644 --- a/fsutil/opread.go +++ b/fsutil/opread.go @@ -85,6 +85,14 @@ func MustRead(in any) []byte { // ReadOrErr read contents from path or io.Reader, will panic on in type error func ReadOrErr(in any) ([]byte, error) { r, err := NewIOReader(in) + defer func() { + if r != nil { + file, ok := r.(*os.File) + if ok { + err = file.Close() + } + } + }() if err != nil { return nil, err }