Skip to content

Possible Nan::Callback leak in async inquire() (the found callback) #493

Description

@OvOhao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions