@@ -72,8 +72,8 @@ uni::CallbackType Reader::NextRows(const uni::FunctionCallbackInfo& args) {
7272void Reader::EIO_NextRows (uv_work_t * req) {
7373 ReaderBaton* baton = static_cast <ReaderBaton*>(req->data );
7474
75- baton->rows = NULL ;
76- baton->error = NULL ;
75+ baton->rows = new vector< row_t *>() ;
76+ if ( baton->done ) return ;
7777
7878 try {
7979 if (! baton->connection ->getConnection ()) {
@@ -96,13 +96,13 @@ void Reader::EIO_NextRows(uv_work_t* req) {
9696 Connection::CreateColumnsFromResultSet (baton->rs , baton, baton->columns );
9797 if (baton->error ) goto cleanup;
9898 }
99- baton->rows = new vector<row_t *>();
10099
101100 for (int i = 0 ; i < baton->count && baton->rs ->next (); i++) {
102101 row_t * row = Connection::CreateRowFromCurrentResultSetRow (baton->rs , baton, baton->columns );
103102 if (baton->error ) goto cleanup;
104103 baton->rows ->push_back (row);
105104 }
105+ if (baton->rows ->size () < (size_t )baton->count ) baton->done = true ;
106106 } catch (oracle::occi::SQLException &ex) {
107107 baton->error = new string (ex.getMessage ());
108108 } catch (const exception& ex) {
@@ -135,5 +135,12 @@ void Reader::EIO_AfterNextRows(uv_work_t* req, int status) {
135135 argv[1 ] = Undefined ();
136136 node::MakeCallback (Context::GetCurrent ()->Global (), cb, 2 , argv);
137137 }
138+
139+ baton->ResetRows ();
140+ if (baton->done || baton->error ) {
141+ // free occi resources so that we don't run out of cursors if gc is not fast enough
142+ // reader destructor will delete the baton and everything else.
143+ baton->ResetStatement ();
144+ }
138145}
139146
0 commit comments