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)
tokarchuk/v1.17
6543 3 years ago committed by GitHub
parent bb4cc876b1
commit d21702475b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      modules/git/blob_nogogit.go
  2. 1
      routers/web/repo/compare.go
  3. 3
      routers/web/repo/issue.go
  4. 6
      routers/web/repo/pull.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

@ -621,7 +621,6 @@ func CompareDiff(ctx *context.Context) {
headGitRepo.Close()
}
}()
if ctx.Written() {
return
}

@ -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) {

@ -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() {

Loading…
Cancel
Save