Possible Nan::Callback leak in inquireSync() (two callbacks per call)
I found a possible native heap leak in inquireSync(). Both Nan::Callbacks are
heap-allocated, used synchronously, and the method returns without deleting either.
File: src/linux/DeviceINQ.cc
Function: DeviceINQ::InquireSync
NAN_METHOD(DeviceINQ::InquireSync) {
...
Nan::Callback *found = new Nan::Callback(info[0].As<Function>());
Nan::Callback *callback = new Nan::Callback(info[1].As<Function>());
bt_inquiry inquiryResult = DeviceINQ::doInquire();
for (int i = 0; i < inquiryResult.num_rsp; i++) { ... found->Call(2, argv); }
callback->Call(0, argv);
return; // found and callback never deleted
}
found and callback are raw heap Nan::Callbacks (each holding a v8::Persistent to
its JS function). They are invoked synchronously and the method returns with no delete
of either, and there is no worker to own them on this synchronous path. Two
Nan::Callbacks leak on every inquireSync() call — a device-scan poll leaks two per
scan.
Suggested fix: delete found; delete callback; before returning (or hold them in owning
smart pointers).
Possible
Nan::Callbackleak ininquireSync()(two callbacks per call)I found a possible native heap leak in
inquireSync(). BothNan::Callbacks areheap-allocated, used synchronously, and the method returns without deleting either.
File:
src/linux/DeviceINQ.ccFunction:
DeviceINQ::InquireSyncfoundandcallbackare raw heapNan::Callbacks (each holding av8::Persistenttoits JS function). They are invoked synchronously and the method returns with no
deleteof either, and there is no worker to own them on this synchronous path. Two
Nan::Callbacks leak on everyinquireSync()call — a device-scan poll leaks two perscan.
Suggested fix:
delete found; delete callback;before returning (or hold them in owningsmart pointers).