aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-08-31 09:43:31 +0200
committerGitHub <noreply@github.com>2021-08-31 08:43:31 +0100
commitd21702475ba43100d3a6e9505a1ae259e4842524 (patch)
treea9163f924f3a0eedda389a557759854312a8b9f0
parentbb4cc876b1d0d5be5aa3fed7827ba3eac8f2ac18 (diff)
downloadgitea-d21702475ba43100d3a6e9505a1ae259e4842524.tar.gz
gitea-d21702475ba43100d3a6e9505a1ae259e4842524.zip
Fix git.Blob.DataAsync(): close pipe since we return a NopCloser (#16899)
* make sure headGitRepo is closed on err too * refactor * Fix git.Blob.DataAsync(): exec cancel since we already read all bytes (close pipe since we return a NopCloser)
-rw-r--r--modules/git/blob_nogogit.go6
-rw-r--r--routers/web/repo/compare.go1
-rw-r--r--routers/web/repo/issue.go3
-rw-r--r--routers/web/repo/pull.go6
4 files changed, 7 insertions, 9 deletions
diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go
index 26815a63f1..3391bc3931 100644
--- a/modules/git/blob_nogogit.go
+++ b/modules/git/blob_nogogit.go
@@ -47,8 +47,8 @@ func (b *Blob) DataAsync() (io.ReadCloser, error) {
if size < 4096 {
bs, err := ioutil.ReadAll(io.LimitReader(rd, size))
+ defer cancel()
if err != nil {
- cancel()
return nil, err
}
_, err = rd.Discard(1)
@@ -106,12 +106,12 @@ func (b *blobReader) Read(p []byte) (n int, err error) {
// Close implements io.Closer
func (b *blobReader) Close() error {
+ defer b.cancel()
if b.n > 0 {
for b.n > math.MaxInt32 {
n, err := b.rd.Discard(math.MaxInt32)
b.n -= int64(n)
if err != nil {
- b.cancel()
return err
}
b.n -= math.MaxInt32
@@ -119,14 +119,12 @@ func (b *blobReader) Close() error {
n, err := b.rd.Discard(int(b.n))
b.n -= int64(n)
if err != nil {
- b.cancel()
return err
}
}
if b.n == 0 {
_, err := b.rd.Discard(1)
b.n--
- b.cancel()
return err
}
return nil
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index ee8d376612..eb6c37a1a6 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -621,7 +621,6 @@ func CompareDiff(ctx *context.Context) {
headGitRepo.Close()
}
}()
-
if ctx.Written() {
return
}
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 3f7af7a51f..bb3a0c8a9c 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -419,9 +419,6 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos
}
handleTeamMentions(ctx)
- if ctx.Written() {
- return
- }
}
func retrieveProjects(ctx *context.Context, repo *models.Repository) {
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 6e83a72c24..8ff2ddf394 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -1024,10 +1024,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
)
headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
+ defer func() {
+ if headGitRepo != nil {
+ headGitRepo.Close()
+ }
+ }()
if ctx.Written() {
return
}
- defer headGitRepo.Close()
labelIDs, assigneeIDs, milestoneID, _ := ValidateRepoMetas(ctx, *form, true)
if ctx.Written() {