Skip to content

Commit

Permalink
Do not double close reader (#29354) (#29370)
Browse files Browse the repository at this point in the history
Backport #29354 by @KN4CK3R

Fixes #29346

Co-authored-by: KN4CK3R <[email protected]>
Co-authored-by: wxiaoguang <[email protected]>
  • Loading branch information
3 people authored Feb 24, 2024
1 parent a1c0b3a commit e75594f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 11 additions & 1 deletion modules/git/blob_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 0 additions & 3 deletions routers/web/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,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 {
Expand Down

0 comments on commit e75594f

Please sign in to comment.