diff --git a/categories/categories.go b/categories/categories.go index 5f8d7f6..98cf500 100644 --- a/categories/categories.go +++ b/categories/categories.go @@ -27,6 +27,7 @@ func LoadCategories(db *sql.DB) { fmt.Println("DB Error loading Categories:", err) return } + defer rows.Close() for rows.Next() { category := &Category{Children: []*Category{}} diff --git a/main.go b/main.go index 84c8a2d..359d98d 100644 --- a/main.go +++ b/main.go @@ -63,13 +63,12 @@ func dbConnect() { if err != nil { fmt.Println("DB ERROR: ", err) } + db.SetMaxIdleConns(MAX_DB_CONNS) err = db.Ping() if err != nil { fmt.Println("DB Error on Ping(): ", err) os.Exit(-1) } - - db.SetMaxIdleConns(MAX_DB_CONNS) } func initTemplates() { diff --git a/news/news.go b/news/news.go index 2457a6e..fef84fa 100644 --- a/news/news.go +++ b/news/news.go @@ -66,6 +66,7 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, int, error) { fmt.Println("DB errpr reading unexported news: ", err) return nil, 0, err } + defer rows.Close() newsTree := map[int]*NewsContainer{} newsFlat := map[int]*NewsContainer{} count := 0 diff --git a/user/user.go b/user/user.go index b499619..58b0dc0 100644 --- a/user/user.go +++ b/user/user.go @@ -17,6 +17,7 @@ func UsernameExists(db *sql.DB, username string) (bool, error) { fmt.Println("User DB Error: ", err) return false, err } + defer rows.Close() var count int rows.Next() rows.Scan(&count) @@ -30,6 +31,7 @@ func NewUserFromAuth(db *sql.DB, username, password string) *User { fmt.Println("Username or auth fail: ", err) return nil } + defer rows.Close() user := User{db: db} if rows.Next() { err := rows.Scan(&user.Username) @@ -49,6 +51,7 @@ func NewUserFromUsername(db *sql.DB, username string) *User { fmt.Println("User DB Error: ", err) return nil } + defer rows.Close() user := User{db: db} if rows.Next() { err = rows.Scan(&user.Username)