From b36a12682b40174bf1bca798fdcc73a45b124756 Mon Sep 17 00:00:00 2001 From: Sven Buijsrogge Date: Thu, 18 Apr 2024 16:09:53 +0200 Subject: [PATCH] [-] fix for nil pointer exception when using .Kind() and closing the rows (#197) Co-authored-by: Sven Buijsrogge --- rows.go | 4 +++- rows_test.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/rows.go b/rows.go index 849aecc..3c94a9b 100644 --- a/rows.go +++ b/rows.go @@ -80,7 +80,9 @@ func (rs *rowSets) FieldDescriptions() []pgconn.FieldDescription { // } func (rs *rowSets) Close() { - rs.ex.rowsWereClosed = true + if rs.ex != nil { + rs.ex.rowsWereClosed = true + } // return rs.sets[rs.pos].closeErr } diff --git a/rows_test.go b/rows_test.go index 364e256..bb312f6 100644 --- a/rows_test.go +++ b/rows_test.go @@ -708,6 +708,10 @@ func TestRowsKind(t *testing.T) { t.Fatalf("expected %s, but got %s", alphabet[i], letter) } } + + // Test closing as this is called by the pgx library in pgx.CollectRows + // Previously this caused a nil pointer exception when Close was called on kindRows + kindRows.Close() } // TestConnRow tests the ConnRow interface implementation for Conn.QueryRow.