1
0
mirror of https://github.com/golang/go synced 2024-11-17 10:24:48 -07:00

database/sql: guard against driver.Stmt.Close panics

Do not retain a lock when driver.Stmt.Close panic as the rest
of the sql package ensures.

Updates #16019

Change-Id: Idc7ea9258ae23f491e79cce3efc365684a708428
Reviewed-on: https://go-review.googlesource.com/33328
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Daniel Theophanes 2016-11-16 11:33:38 -08:00 committed by Ian Lance Taylor
parent 81627f0e47
commit 49b77a8797

View File

@ -408,17 +408,19 @@ func (dc *driverConn) Close() error {
} }
func (dc *driverConn) finalClose() error { func (dc *driverConn) finalClose() error {
dc.Lock() var err error
withLock(dc, func() {
defer func() { // In case si.Close panics.
dc.openStmt = nil
dc.finalClosed = true
err = dc.ci.Close()
dc.ci = nil
}()
for si := range dc.openStmt { for si := range dc.openStmt {
si.Close() si.Close()
} }
dc.openStmt = nil })
err := dc.ci.Close()
dc.ci = nil
dc.finalClosed = true
dc.Unlock()
dc.db.mu.Lock() dc.db.mu.Lock()
dc.db.numOpen-- dc.db.numOpen--