close connection when got errors in Open

This commit is contained in:
Yasuhiro Matsumoto 2017-03-24 08:48:29 +09:00
parent 866c3293d9
commit fc03fa9989
1 changed files with 3 additions and 0 deletions

View File

@ -609,6 +609,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
rv = C.sqlite3_busy_timeout(db, C.int(busyTimeout)) rv = C.sqlite3_busy_timeout(db, C.int(busyTimeout))
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
conn.Close()
return nil, Error{Code: ErrNo(rv)} return nil, Error{Code: ErrNo(rv)}
} }
@ -616,12 +617,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
if len(d.Extensions) > 0 { if len(d.Extensions) > 0 {
if err := conn.loadExtensions(d.Extensions); err != nil { if err := conn.loadExtensions(d.Extensions); err != nil {
conn.Close()
return nil, err return nil, err
} }
} }
if d.ConnectHook != nil { if d.ConnectHook != nil {
if err := d.ConnectHook(conn); err != nil { if err := d.ConnectHook(conn); err != nil {
conn.Close()
return nil, err return nil, err
} }
} }