Skip to content

Commit 569232d

Browse files
committed
fix possibly double Close.
fixes #448
1 parent 47fc4e5 commit 569232d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

sqlite3.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ type SQLiteDriver struct {
167167

168168
// SQLiteConn implement sql.Conn.
169169
type SQLiteConn struct {
170-
dbMu sync.Mutex
170+
mu sync.Mutex
171171
db *C.sqlite3
172172
loc *time.Location
173173
txlock string
@@ -197,6 +197,7 @@ type SQLiteResult struct {
197197

198198
// SQLiteRows implement sql.Rows.
199199
type SQLiteRows struct {
200+
mu sync.Mutex
200201
s *SQLiteStmt
201202
nc int
202203
cols []string
@@ -761,9 +762,9 @@ func (c *SQLiteConn) Close() error {
761762
return c.lastError()
762763
}
763764
deleteHandles(c)
764-
c.dbMu.Lock()
765+
c.mu.Lock()
765766
c.db = nil
766-
c.dbMu.Unlock()
767+
c.mu.Unlock()
767768
runtime.SetFinalizer(c, nil)
768769
return nil
769770
}
@@ -772,8 +773,8 @@ func (c *SQLiteConn) dbConnOpen() bool {
772773
if c == nil {
773774
return false
774775
}
775-
c.dbMu.Lock()
776-
defer c.dbMu.Unlock()
776+
c.mu.Lock()
777+
defer c.mu.Unlock()
777778
return c.db != nil
778779
}
779780

@@ -980,7 +981,10 @@ func (rc *SQLiteRows) Close() error {
980981
return nil
981982
}
982983
if rc.done != nil {
984+
rc.mu.Lock()
983985
close(rc.done)
986+
rc.done = nil
987+
rc.mu.Unlock()
984988
}
985989
if rc.cls {
986990
return rc.s.Close()
File renamed without changes.

0 commit comments

Comments
 (0)