Commit 49b77a87 authored by Daniel Theophanes's avatar Daniel Theophanes Committed by Ian Lance Taylor

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 81627f0e
......@@ -408,17 +408,19 @@ func (dc *driverConn) Close() error {
}
func (dc *driverConn) finalClose() error {
dc.Lock()
for si := range dc.openStmt {
si.Close()
}
dc.openStmt = nil
err := dc.ci.Close()
dc.ci = nil
dc.finalClosed = true
dc.Unlock()
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 {
si.Close()
}
})
dc.db.mu.Lock()
dc.db.numOpen--
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment