Skip to content

Commit

Permalink
Close the dataRC reader sooner
Browse files Browse the repository at this point in the history
Fix go-gitea#15932

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed May 29, 2021
1 parent a9daebc commit d0ff409
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion routers/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.NotFound("blob.Data", err)
return
}
defer dataRc.Close()
closed := false

defer func() {
if !closed {
dataRc.Close()
}
}()

ctx.Data["FileSize"] = blob.Size()
ctx.Data["FileName"] = blob.Name()
Expand All @@ -122,6 +128,11 @@ func editFile(ctx *context.Context, isNewFile bool) {
}

d, _ := ioutil.ReadAll(dataRc)
if err := dataRc.Close(); err != nil {
log.Error("Error whilst closing blob data: %v", err)
}
closed = true

buf = append(buf, d...)
if content, err := charset.ToUTF8WithErr(buf); err != nil {
log.Error("ToUTF8WithErr: %v", err)
Expand Down

0 comments on commit d0ff409

Please sign in to comment.