From db814becb7a7424bdc2d68bc269e5193c616c3b9 Mon Sep 17 00:00:00 2001 From: Yaroslav Novytskyy Date: Fri, 28 Apr 2023 09:58:50 -0400 Subject: [PATCH] fix nil pointer dereference --- sql.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sql.go b/sql.go index a31d99c..fe030cc 100644 --- a/sql.go +++ b/sql.go @@ -76,12 +76,13 @@ func (*SQL) Open(database string, connectionString string) (*dbsql.DB, error) { // providing results as a slice of KeyValue instance(s) if available. func (*SQL) Query(db *dbsql.DB, query string, args ...interface{}) ([]KeyValue, error) { rows, err := db.Query(query, args...) - defer func() { - _ = rows.Close() - }() if err != nil { return nil, err } + + defer func() { + _ = rows.Close() + }() if rows.Err() != nil { return nil, rows.Err() }