Skip to content

Commit d2f547a

Browse files
committed
Prevent NPE on invalid diff
If ParseCompareInfo returns a nil compare info the defer function needs to ensure that it does not attempt to close the HeadGitRepo. Fix #17193 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 3bbdce2 commit d2f547a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

routers/web/repo/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ func getBranchesAndTagsForRepo(user *models.User, repo *models.Repository) (bool
635635
func CompareDiff(ctx *context.Context) {
636636
ci := ParseCompareInfo(ctx)
637637
defer func() {
638-
if ci.HeadGitRepo != nil {
638+
if ci != nil && ci.HeadGitRepo != nil {
639639
ci.HeadGitRepo.Close()
640640
}
641641
}()

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
10431043

10441044
ci := ParseCompareInfo(ctx)
10451045
defer func() {
1046-
if ci.HeadGitRepo != nil {
1046+
if ci != nil && ci.HeadGitRepo != nil {
10471047
ci.HeadGitRepo.Close()
10481048
}
10491049
}()

0 commit comments

Comments
 (0)