From fc03fa998970a0110f9727c0441985b35ab50055 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 24 Mar 2017 08:48:29 +0900 Subject: [PATCH] close connection when got errors in Open --- sqlite3.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sqlite3.go b/sqlite3.go index 3a9a4dd..375cf79 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -609,6 +609,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { rv = C.sqlite3_busy_timeout(db, C.int(busyTimeout)) if rv != C.SQLITE_OK { + conn.Close() 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 err := conn.loadExtensions(d.Extensions); err != nil { + conn.Close() return nil, err } } if d.ConnectHook != nil { if err := d.ConnectHook(conn); err != nil { + conn.Close() return nil, err } }