Skip to content

Commit 1de9784

Browse files
committed
fixed memory/cursor leak in reader
1 parent 44f1308 commit 1de9784

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/reader.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ uni::CallbackType Reader::NextRows(const uni::FunctionCallbackInfo& args) {
5353
REQ_INT_ARG(0, count);
5454
REQ_FUN_ARG(1, callback);
5555
baton->count = count;
56-
uni::Reset(baton->callback, callback);
56+
uni::Reset(baton->nextRowsCallback, callback);
5757
} else {
5858
REQ_FUN_ARG(0, callback);
5959
baton->count = baton->connection->getPrefetchRowCount();
60-
uni::Reset(baton->callback, callback);
60+
uni::Reset(baton->nextRowsCallback, callback);
6161
}
6262
if (baton->count <= 0) baton->count = 1;
6363

@@ -115,6 +115,18 @@ void Reader::EIO_NextRows(uv_work_t* req) {
115115
;
116116
}
117117

118+
#if NODE_MODULE_VERSION >= 0x000D
119+
void ReaderWeakReferenceCallback(Isolate* isolate, v8::Persistent<v8::Function>* callback, void* dummy)
120+
{
121+
callback->Dispose();
122+
}
123+
#else
124+
void ReaderWeakReferenceCallback(v8::Persistent<v8::Value> callback, void* dummy)
125+
{
126+
(Persistent<Function>(Function::Cast(*callback))).Dispose();
127+
}
128+
#endif
129+
118130
void Reader::EIO_AfterNextRows(uv_work_t* req, int status) {
119131
UNI_SCOPE(scope);
120132
ReaderBaton* baton = static_cast<ReaderBaton*>(req->data);
@@ -124,12 +136,13 @@ void Reader::EIO_AfterNextRows(uv_work_t* req, int status) {
124136
try {
125137
Handle<Value> argv[2];
126138
Connection::handleResult(baton, argv);
127-
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv);
139+
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->nextRowsCallback), 2, argv);
128140
} catch(const exception &ex) {
129141
Handle<Value> argv[2];
130142
argv[0] = Exception::Error(String::New(ex.what()));
131143
argv[1] = Undefined();
132-
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv);
144+
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->nextRowsCallback), 2, argv);
133145
}
146+
baton->nextRowsCallback.MakeWeak((void*)NULL, ReaderWeakReferenceCallback);
134147
}
135148

src/readerBaton.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ReaderBaton : public ExecuteBaton {
2424
}
2525
}
2626

27+
v8::Persistent<v8::Function> nextRowsCallback;
2728
oracle::occi::Statement* stmt;
2829
oracle::occi::ResultSet* rs;
2930
int count;

0 commit comments

Comments
 (0)