fix possibly double Close.

fixes #448
This commit is contained in:
Yasuhiro Matsumoto 2017-08-02 00:06:18 +09:00
parent 47fc4e5e91
commit 569232dc08
2 changed files with 9 additions and 5 deletions

View File

@ -167,7 +167,7 @@ type SQLiteDriver struct {
// SQLiteConn implement sql.Conn. // SQLiteConn implement sql.Conn.
type SQLiteConn struct { type SQLiteConn struct {
dbMu sync.Mutex mu sync.Mutex
db *C.sqlite3 db *C.sqlite3
loc *time.Location loc *time.Location
txlock string txlock string
@ -197,6 +197,7 @@ type SQLiteResult struct {
// SQLiteRows implement sql.Rows. // SQLiteRows implement sql.Rows.
type SQLiteRows struct { type SQLiteRows struct {
mu sync.Mutex
s *SQLiteStmt s *SQLiteStmt
nc int nc int
cols []string cols []string
@ -761,9 +762,9 @@ func (c *SQLiteConn) Close() error {
return c.lastError() return c.lastError()
} }
deleteHandles(c) deleteHandles(c)
c.dbMu.Lock() c.mu.Lock()
c.db = nil c.db = nil
c.dbMu.Unlock() c.mu.Unlock()
runtime.SetFinalizer(c, nil) runtime.SetFinalizer(c, nil)
return nil return nil
} }
@ -772,8 +773,8 @@ func (c *SQLiteConn) dbConnOpen() bool {
if c == nil { if c == nil {
return false return false
} }
c.dbMu.Lock() c.mu.Lock()
defer c.dbMu.Unlock() defer c.mu.Unlock()
return c.db != nil return c.db != nil
} }
@ -980,7 +981,10 @@ func (rc *SQLiteRows) Close() error {
return nil return nil
} }
if rc.done != nil { if rc.done != nil {
rc.mu.Lock()
close(rc.done) close(rc.done)
rc.done = nil
rc.mu.Unlock()
} }
if rc.cls { if rc.cls {
return rc.s.Close() return rc.s.Close()