Skip to content

Commit 0274933

Browse files
6543zeripath
andauthored
Fix git.Blob.DataAsync(): close pipe since we return a NopCloser (#16899) (#16900)
* 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) Co-authored-by: zeripath <[email protected]>
1 parent 6777637 commit 0274933

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
@@ -46,8 +46,8 @@ func (b *Blob) DataAsync() (io.ReadCloser, error) {
4646

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

106106
// Close implements io.Closer
107107
func (b *blobReader) Close() error {
108+
defer b.cancel()
108109
if b.n > 0 {
109110
for b.n > math.MaxInt32 {
110111
n, err := b.rd.Discard(math.MaxInt32)
111112
b.n -= int64(n)
112113
if err != nil {
113-
b.cancel()
114114
return err
115115
}
116116
b.n -= math.MaxInt32
117117
}
118118
n, err := b.rd.Discard(int(b.n))
119119
b.n -= int64(n)
120120
if err != nil {
121-
b.cancel()
122121
return err
123122
}
124123
}
125124
if b.n == 0 {
126125
_, err := b.rd.Discard(1)
127126
b.n--
128-
b.cancel()
129127
return err
130128
}
131129
return nil

routers/web/repo/compare.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ func CompareDiff(ctx *context.Context) {
623623
headGitRepo.Close()
624624
}
625625
}()
626-
627626
if ctx.Written() {
628627
return
629628
}

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
@@ -1012,10 +1012,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
10121012
)
10131013

10141014
headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
1015+
defer func() {
1016+
if headGitRepo != nil {
1017+
headGitRepo.Close()
1018+
}
1019+
}()
10151020
if ctx.Written() {
10161021
return
10171022
}
1018-
defer headGitRepo.Close()
10191023

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

0 commit comments

Comments
 (0)