Fix race in SQLiteStmt.Close by holding conn lock across cache check
This commit is contained in:
16
sqlite3.go
16
sqlite3.go
@@ -1970,6 +1970,10 @@ func (c *SQLiteConn) putCachedStmt(s *SQLiteStmt) bool {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
return c.putCachedStmtLocked(s)
|
||||
}
|
||||
|
||||
func (c *SQLiteConn) putCachedStmtLocked(s *SQLiteStmt) bool {
|
||||
if c.db == nil {
|
||||
return false
|
||||
}
|
||||
@@ -2164,12 +2168,20 @@ func (s *SQLiteStmt) Close() error {
|
||||
s.c = nil
|
||||
return nil
|
||||
}
|
||||
if !conn.dbConnOpen() {
|
||||
if s.cacheKey != "" {
|
||||
conn.mu.Lock()
|
||||
if conn.db == nil {
|
||||
conn.mu.Unlock()
|
||||
return errors.New("sqlite statement with already closed database connection")
|
||||
}
|
||||
if s.cacheKey != "" && conn.putCachedStmt(s) {
|
||||
if conn.putCachedStmtLocked(s) {
|
||||
conn.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
conn.mu.Unlock()
|
||||
} else if !conn.dbConnOpen() {
|
||||
return errors.New("sqlite statement with already closed database connection")
|
||||
}
|
||||
s.s = nil
|
||||
s.c = nil
|
||||
rv := C.sqlite3_finalize(stmt)
|
||||
|
||||
Reference in New Issue
Block a user