From 7ddeb101ca2d6ee60b14596e6247ea5f67a40f78 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Wed, 26 Aug 2015 01:19:28 -0400 Subject: [PATCH] Fix NPEs in SQL Next and Contains --- graph/sql/all_iterator.go | 3 +++ graph/sql/sql_iterator.go | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/graph/sql/all_iterator.go b/graph/sql/all_iterator.go index 05f94b3..c91c65d 100644 --- a/graph/sql/all_iterator.go +++ b/graph/sql/all_iterator.go @@ -131,6 +131,9 @@ func (it *AllIterator) Next() bool { graph.NextLogIn(it) if it.cursor == nil { it.makeCursor() + if it.cursor == nil { + return false + } } if !it.cursor.Next() { glog.V(4).Infoln("sql: No next") diff --git a/graph/sql/sql_iterator.go b/graph/sql/sql_iterator.go index 74ca0c2..79df549 100644 --- a/graph/sql/sql_iterator.go +++ b/graph/sql/sql_iterator.go @@ -151,6 +151,11 @@ func (it *SQLIterator) Next() bool { graph.NextLogIn(it) if it.cursor == nil { err = it.makeCursor(true, nil) + if err != nil { + glog.Errorf("Couldn't make query: %v", err) + it.err = err + return false + } it.cols, err = it.cursor.Columns() if err != nil { glog.Errorf("Couldn't get columns") @@ -226,7 +231,9 @@ func (it *SQLIterator) Contains(v graph.Value) bool { if err != nil { glog.Errorf("Couldn't make query: %v", err) it.err = err - it.cursor.Close() + if it.cursor != nil { + it.cursor.Close() + } return false } it.cols, err = it.cursor.Columns()