Skip to content

Commit d0ff409

Browse files
committed
Close the dataRC reader sooner
Fix go-gitea#15932 Signed-off-by: Andrew Thornton <[email protected]>
1 parent a9daebc commit d0ff409

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

routers/repo/editor.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ func editFile(ctx *context.Context, isNewFile bool) {
106106
ctx.NotFound("blob.Data", err)
107107
return
108108
}
109-
defer dataRc.Close()
109+
closed := false
110+
111+
defer func() {
112+
if !closed {
113+
dataRc.Close()
114+
}
115+
}()
110116

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

124130
d, _ := ioutil.ReadAll(dataRc)
131+
if err := dataRc.Close(); err != nil {
132+
log.Error("Error whilst closing blob data: %v", err)
133+
}
134+
closed = true
135+
125136
buf = append(buf, d...)
126137
if content, err := charset.ToUTF8WithErr(buf); err != nil {
127138
log.Error("ToUTF8WithErr: %v", err)

0 commit comments

Comments
 (0)