From 64ef7d365872b3a6160488c9fb5f652ec3e6413c Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sat, 24 Feb 2024 12:45:59 +0100 Subject: [PATCH] Do not double close reader (#29354) Fixes #29346 --------- Co-authored-by: wxiaoguang (cherry picked from commit 553d46e6f6a144905266d58315a2b0ff2e976380) --- modules/git/blob_nogogit.go | 12 +++++++++++- routers/web/repo/editor.go | 3 --- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go index 9e1c2a037..945a6bc43 100644 --- a/modules/git/blob_nogogit.go +++ b/modules/git/blob_nogogit.go @@ -102,7 +102,17 @@ func (b *blobReader) Read(p []byte) (n int, err error) { // Close implements io.Closer func (b *blobReader) Close() error { + if b.rd == nil { + return nil + } + defer b.cancel() - return DiscardFull(b.rd, b.n+1) + if err := DiscardFull(b.rd, b.n+1); err != nil { + return err + } + + b.rd = nil + + return nil } diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 7a0501604..93decc085 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -183,9 +183,6 @@ func editFile(ctx *context.Context, isNewFile bool) { } d, _ := io.ReadAll(dataRc) - if err := dataRc.Close(); err != nil { - log.Error("Error whilst closing blob data: %v", err) - } buf = append(buf, d...) if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil {