Possible Nan::Callback leak in async inquire() (the found callback)
I found a possible native heap leak in the async inquire() path. InquireWorker
stores a second found callback that the base Nan::AsyncWorker does not own, and the
subclass destructor never frees it.
File: src/linux/DeviceINQ.cc
Functions: InquireWorker, DeviceINQ::Inquire
class InquireWorker : public Nan::AsyncWorker {
public:
InquireWorker(Nan::Callback* found, Nan::Callback *callback)
: Nan::AsyncWorker(callback), found(found) {}
~InquireWorker() {} // does not delete found
...
private:
Nan::Callback* found;
};
NAN_METHOD(DeviceINQ::Inquire) {
...
Nan::Callback *found = new Nan::Callback(info[0].As<Function>());
Nan::Callback *callback = new Nan::Callback(info[1].As<Function>());
Nan::AsyncQueueWorker(new InquireWorker(found, callback));
}
Nan::AsyncWorker's base destructor deletes only the callback it was constructed with.
found is a separate member and ~InquireWorker() is empty, so found (a heap
Nan::Callback retaining a v8::Persistent to the JS function) leaks on every
inquire() call.
Suggested fix: delete found; in ~InquireWorker(), or store found in an owning smart
pointer.
Possible
Nan::Callbackleak in asyncinquire()(thefoundcallback)I found a possible native heap leak in the async
inquire()path.InquireWorkerstores a second
foundcallback that the baseNan::AsyncWorkerdoes not own, and thesubclass destructor never frees it.
File:
src/linux/DeviceINQ.ccFunctions:
InquireWorker,DeviceINQ::InquireNan::AsyncWorker's base destructor deletes only thecallbackit was constructed with.foundis a separate member and~InquireWorker()is empty, sofound(a heapNan::Callbackretaining av8::Persistentto the JS function) leaks on everyinquire()call.Suggested fix:
delete found;in~InquireWorker(), or storefoundin an owning smartpointer.