Memory leaks in addon callback


#1

Used electron 1.2.5 with such code:

Renderer:
main = require('electron').remote.getGlobal('Main'); main.GetData(function(data){ //...do some stuff });

Main:
const addon = require('./addon.node'); global.Main = new Main(); Main.prototype.GetData = function(callback){ addon.GetData(callback); }

Addon, code is more complex but the main idea next:
void GetData(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate);

auto arr = std::vector<BYTE>(2000); auto buf = node::Buffer::Copy(is, (char*)&arr[0], arr.size()).ToLocalChecked();

std::vector<Local<Value>> argv; argv.push_back(buf);

auto JSCallback = GetCallback(isolate, args[0]); jSCallback->Call(is->GetCurrentContext(), Null(is), argv.size(), &argv[0]); }

Such code produces memory leaks. If callback is not called from addon or callback was defined in Main, not in Renderer - no memory leaks occur. Also no leaks if in main I’m sending data to renderer with IPC.

How to avoid this memory leak, or there is some bug for this situation?