Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git.Blob.DataAsync(): close pipe since we return a NopCloser #16899

Merged
merged 5 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions modules/git/blob_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -106,27 +106,25 @@ 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
}
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
Expand Down
1 change: 0 additions & 1 deletion routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ func CompareDiff(ctx *context.Context) {
headGitRepo.Close()
}
}()

if ctx.Written() {
return
}
Expand Down
3 changes: 0 additions & 3 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,6 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos
}

handleTeamMentions(ctx)
if ctx.Written() {
zeripath marked this conversation as resolved.
Show resolved Hide resolved
return
}
}

func retrieveProjects(ctx *context.Context, repo *models.Repository) {
Expand Down
6 changes: 5 additions & 1 deletion routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
)

headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
defer func() {
lunny marked this conversation as resolved.
Show resolved Hide resolved
if headGitRepo != nil {
headGitRepo.Close()
}
}()
if ctx.Written() {
return
}
defer headGitRepo.Close()

labelIDs, assigneeIDs, milestoneID, _ := ValidateRepoMetas(ctx, *form, true)
if ctx.Written() {
Expand Down