summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-04-11 04:49:10 +0800
committerGitHub <noreply@github.com>2021-04-10 16:49:10 -0400
commit1fc1d605178ead73e31d6e068af3f3e38c28a803 (patch)
treea2889951382b582255bc0bec51669fe6d41b6e14 /models
parentc680eb2cc74823f017f5ad5a4c9e8094cde311f4 (diff)
downloadgitea-1fc1d605178ead73e31d6e068af3f3e38c28a803.tar.gz
gitea-1fc1d605178ead73e31d6e068af3f3e38c28a803.zip
Fix delete nonexist oauth application 500 and prevent deadlock (#15384)
* Fix delete nonexist oauth application 500 * Fix test * Close the session Signed-off-by: Andrew Thornton <art27@cantab.net> * Update integrations/api_oauth2_apps_test.go * Fix more missed sess.Close * Remove unnecessary blank line Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models')
-rw-r--r--models/migrate.go2
-rw-r--r--models/oauth2_application.go3
2 files changed, 4 insertions, 1 deletions
diff --git a/models/migrate.go b/models/migrate.go
index 9e44f32e54..28b6707473 100644
--- a/models/migrate.go
+++ b/models/migrate.go
@@ -39,6 +39,7 @@ func InsertMilestones(ms ...*Milestone) (err error) {
// InsertIssues insert issues to database
func InsertIssues(issues ...*Issue) error {
sess := x.NewSession()
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
@@ -194,6 +195,7 @@ func InsertPullRequests(prs ...*PullRequest) error {
// InsertReleases migrates release
func InsertReleases(rels ...*Release) error {
sess := x.NewSession()
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
diff --git a/models/oauth2_application.go b/models/oauth2_application.go
index 1b544e4e9e..679fdb18f9 100644
--- a/models/oauth2_application.go
+++ b/models/oauth2_application.go
@@ -235,7 +235,7 @@ func deleteOAuth2Application(sess *xorm.Session, id, userid int64) error {
if deleted, err := sess.Delete(&OAuth2Application{ID: id, UID: userid}); err != nil {
return err
} else if deleted == 0 {
- return fmt.Errorf("cannot find oauth2 application")
+ return ErrOAuthApplicationNotFound{ID: id}
}
codes := make([]*OAuth2AuthorizationCode, 0)
// delete correlating auth codes
@@ -261,6 +261,7 @@ func deleteOAuth2Application(sess *xorm.Session, id, userid int64) error {
// DeleteOAuth2Application deletes the application with the given id and the grants and auth codes related to it. It checks if the userid was the creator of the app.
func DeleteOAuth2Application(id, userid int64) error {
sess := x.NewSession()
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}