Skip to content

Possible Nan::Callback leak in inquireSync() (two callbacks per call) #492

Description

@OvOhao

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).

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