From 3709d0698b4327ce7b06f6a3e1a4f8816ce321f1 Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Thu, 10 Oct 2019 20:40:24 +0800 Subject: [PATCH] go: Close all DB results --- GoBot/db_invite.go | 1 + GoBot/db_vote.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/GoBot/db_invite.go b/GoBot/db_invite.go index 7ce9619..8e752ad 100644 --- a/GoBot/db_invite.go +++ b/GoBot/db_invite.go @@ -9,6 +9,7 @@ func getInviteOwner(inviteCode string) (string, error) { if err != nil { return "", err } + defer rows.Close() if rows.Next() { var owner string var used bool diff --git a/GoBot/db_vote.go b/GoBot/db_vote.go index bf285af..6562f9b 100644 --- a/GoBot/db_vote.go +++ b/GoBot/db_vote.go @@ -27,6 +27,7 @@ func getVoteName(id int) (string, error) { if err != nil { return "", err } + defer rows.Close() if rows.Next() { var name string err := rows.Scan(&name) @@ -43,6 +44,7 @@ func getVoteFromMessageID(msgID string) (int, error) { if err != nil { return 0, err } + defer rows.Close() if rows.Next() { var id int err := rows.Scan(&id) @@ -64,10 +66,12 @@ func updateVote(voteID int, userID string, voteValue int) error { if rows.Next() { return errForceRejectionVoteReuse } + rows.Close() } //Check if the vote is finished and don't allow change of vote that way. rows, err := db.Query("SELECT finished FROM vote WHERE id=? AND finished=?", voteID, true) + defer rows.Close() if rows.Next() { return errVoteIsOver }