From 72a60c5df47bbb6940d803c1e744e37126a102fb Mon Sep 17 00:00:00 2001 From: Vladislav Moskovets Date: Fri, 31 Mar 2017 14:26:51 +0300 Subject: [PATCH] prevent nil pointer dereference on closed connection --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 9ae560a1..0648bdb9 100644 --- a/main.go +++ b/main.go @@ -452,7 +452,7 @@ func (s *DB) Debug() *DB { // Begin begin a transaction func (s *DB) Begin() *DB { c := s.clone() - if db, ok := c.db.(sqlDb); ok { + if db, ok := c.db.(sqlDb); ok && db != nil { tx, err := db.Begin() c.db = interface{}(tx).(SQLCommon) c.AddError(err) @@ -464,7 +464,7 @@ func (s *DB) Begin() *DB { // Commit commit a transaction func (s *DB) Commit() *DB { - if db, ok := s.db.(sqlTx); ok { + if db, ok := s.db.(sqlTx); ok && db != nil { s.AddError(db.Commit()) } else { s.AddError(ErrInvalidTransaction) @@ -474,7 +474,7 @@ func (s *DB) Commit() *DB { // Rollback rollback a transaction func (s *DB) Rollback() *DB { - if db, ok := s.db.(sqlTx); ok { + if db, ok := s.db.(sqlTx); ok && db != nil { s.AddError(db.Rollback()) } else { s.AddError(ErrInvalidTransaction)