Skip to content

Commit

Permalink
prevent nil pointer dereference on closed connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Moskovets committed Mar 31, 2017
1 parent 45ccb13 commit 72a60c5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 72a60c5

Please sign in to comment.