Skip to content

Commit 6944bb2

Browse files
committed
fixed memory management of reader callback
1 parent 1de9784 commit 6944bb2

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/reader.cpp

Lines changed: 8 additions & 17 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->nextRowsCallback, callback);
56+
uni::Reset(baton->callback, callback);
5757
} else {
5858
REQ_FUN_ARG(0, callback);
5959
baton->count = baton->connection->getPrefetchRowCount();
60-
uni::Reset(baton->nextRowsCallback, callback);
60+
uni::Reset(baton->callback, callback);
6161
}
6262
if (baton->count <= 0) baton->count = 1;
6363

@@ -115,34 +115,25 @@ 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-
130118
void Reader::EIO_AfterNextRows(uv_work_t* req, int status) {
131119
UNI_SCOPE(scope);
132120
ReaderBaton* baton = static_cast<ReaderBaton*>(req->data);
133121

134122
baton->connection->Unref();
123+
// transfer callback to local and dispose persistent handle
124+
// must be done before invoking callback because callback may set another callback into baton->callback
125+
Local<Function> cb = uni::Deref(baton->callback);
126+
baton->callback.Dispose();
135127

136128
try {
137129
Handle<Value> argv[2];
138130
Connection::handleResult(baton, argv);
139-
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->nextRowsCallback), 2, argv);
131+
node::MakeCallback(Context::GetCurrent()->Global(), cb, 2, argv);
140132
} catch(const exception &ex) {
141133
Handle<Value> argv[2];
142134
argv[0] = Exception::Error(String::New(ex.what()));
143135
argv[1] = Undefined();
144-
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->nextRowsCallback), 2, argv);
136+
node::MakeCallback(Context::GetCurrent()->Global(), cb, 2, argv);
145137
}
146-
baton->nextRowsCallback.MakeWeak((void*)NULL, ReaderWeakReferenceCallback);
147138
}
148139

src/readerBaton.h

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

27-
v8::Persistent<v8::Function> nextRowsCallback;
2827
oracle::occi::Statement* stmt;
2928
oracle::occi::ResultSet* rs;
3029
int count;

0 commit comments

Comments
 (0)