Skip to content

Commit d217024

Browse files
authored
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)
1 parent bb4cc87 commit d217024

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

modules/git/blob_nogogit.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func (b *Blob) DataAsync() (io.ReadCloser, error) {
4747

4848
if size < 4096 {
4949
bs, err := ioutil.ReadAll(io.LimitReader(rd, size))
50+
defer cancel()
5051
if err != nil {
51-
cancel()
5252
return nil, err
5353
}
5454
_, err = rd.Discard(1)
@@ -106,27 +106,25 @@ func (b *blobReader) Read(p []byte) (n int, err error) {
106106

107107
// Close implements io.Closer
108108
func (b *blobReader) Close() error {
109+
defer b.cancel()
109110
if b.n > 0 {
110111
for b.n > math.MaxInt32 {
111112
n, err := b.rd.Discard(math.MaxInt32)
112113
b.n -= int64(n)
113114
if err != nil {
114-
b.cancel()
115115
return err
116116
}
117117
b.n -= math.MaxInt32
118118
}
119119
n, err := b.rd.Discard(int(b.n))
120120
b.n -= int64(n)
121121
if err != nil {
122-
b.cancel()
123122
return err
124123
}
125124
}
126125
if b.n == 0 {
127126
_, err := b.rd.Discard(1)
128127
b.n--
129-
b.cancel()
130128
return err
131129
}
132130
return nil

routers/web/repo/compare.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ func CompareDiff(ctx *context.Context) {
621621
headGitRepo.Close()
622622
}
623623
}()
624-
625624
if ctx.Written() {
626625
return
627626
}

routers/web/repo/issue.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,6 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos
419419
}
420420

421421
handleTeamMentions(ctx)
422-
if ctx.Written() {
423-
return
424-
}
425422
}
426423

427424
func retrieveProjects(ctx *context.Context, repo *models.Repository) {

routers/web/repo/pull.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,10 +1024,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
10241024
)
10251025

10261026
headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
1027+
defer func() {
1028+
if headGitRepo != nil {
1029+
headGitRepo.Close()
1030+
}
1031+
}()
10271032
if ctx.Written() {
10281033
return
10291034
}
1030-
defer headGitRepo.Close()
10311035

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

0 commit comments

Comments
 (0)