summaryrefslogtreecommitdiffstats
path: root/modules/lfs
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-10-10 18:42:28 +0100
committerGitHub <noreply@github.com>2019-10-10 18:42:28 +0100
commit6551a9d6ca8ab79fe1460eb9d60a5a0e76110eb3 (patch)
tree2fe5e28d14acfc2d59e40af7f6844e064932cb89 /modules/lfs
parentdf2c11a878719719b8600745888c570af93827be (diff)
downloadgitea-6551a9d6ca8ab79fe1460eb9d60a5a0e76110eb3.tar.gz
gitea-6551a9d6ca8ab79fe1460eb9d60a5a0e76110eb3.zip
Ensure Request Body Readers are closed in LFS server (#8454)
Diffstat (limited to 'modules/lfs')
-rw-r--r--modules/lfs/locks.go8
-rw-r--r--modules/lfs/server.go12
2 files changed, 15 insertions, 5 deletions
diff --git a/modules/lfs/locks.go b/modules/lfs/locks.go
index d7b2429698..9ffe6b9d59 100644
--- a/modules/lfs/locks.go
+++ b/modules/lfs/locks.go
@@ -155,7 +155,9 @@ func PostLockHandler(ctx *context.Context) {
}
var req api.LFSLockRequest
- dec := json.NewDecoder(ctx.Req.Body().ReadCloser())
+ bodyReader := ctx.Req.Body().ReadCloser()
+ defer bodyReader.Close()
+ dec := json.NewDecoder(bodyReader)
if err := dec.Decode(&req); err != nil {
writeStatus(ctx, 400)
return
@@ -269,7 +271,9 @@ func UnLockHandler(ctx *context.Context) {
}
var req api.LFSLockDeleteRequest
- dec := json.NewDecoder(ctx.Req.Body().ReadCloser())
+ bodyReader := ctx.Req.Body().ReadCloser()
+ defer bodyReader.Close()
+ dec := json.NewDecoder(bodyReader)
if err := dec.Decode(&req); err != nil {
writeStatus(ctx, 400)
return
diff --git a/modules/lfs/server.go b/modules/lfs/server.go
index 652610acf4..6fa97a2894 100644
--- a/modules/lfs/server.go
+++ b/modules/lfs/server.go
@@ -327,7 +327,9 @@ func PutHandler(ctx *context.Context) {
}
contentStore := &ContentStore{BasePath: setting.LFS.ContentPath}
- if err := contentStore.Put(meta, ctx.Req.Body().ReadCloser()); err != nil {
+ bodyReader := ctx.Req.Body().ReadCloser()
+ defer bodyReader.Close()
+ if err := contentStore.Put(meta, bodyReader); err != nil {
ctx.Resp.WriteHeader(500)
fmt.Fprintf(ctx.Resp, `{"message":"%s"}`, err)
if err = repository.RemoveLFSMetaObjectByOid(rv.Oid); err != nil {
@@ -434,7 +436,9 @@ func unpack(ctx *context.Context) *RequestVars {
if r.Method == "POST" { // Maybe also check if +json
var p RequestVars
- dec := json.NewDecoder(r.Body().ReadCloser())
+ bodyReader := r.Body().ReadCloser()
+ defer bodyReader.Close()
+ dec := json.NewDecoder(bodyReader)
err := dec.Decode(&p)
if err != nil {
return rv
@@ -453,7 +457,9 @@ func unpackbatch(ctx *context.Context) *BatchVars {
r := ctx.Req
var bv BatchVars
- dec := json.NewDecoder(r.Body().ReadCloser())
+ bodyReader := r.Body().ReadCloser()
+ defer bodyReader.Close()
+ dec := json.NewDecoder(bodyReader)
err := dec.Decode(&bv)
if err != nil {
return &bv