From f51192bc4d233087f2a1a04b542bb42866026714 Mon Sep 17 00:00:00 2001 From: Alexey Kozyatinskiy Date: Wed, 15 Nov 2017 08:33:13 -0800 Subject: [PATCH] [inspector] fixed CommandLineAPIData leak We can use v8::ArrayBuffer to store struct. R=dgozman@chromium.org Bug: none Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I6c4e994e3a8b0a19ad06f89dfadf808f8c6a68e6 Reviewed-on: https://chromium-review.googlesource.com/772036 Reviewed-by: Dmitry Gozman Commit-Queue: Aleksey Kozyatinskiy Cr-Commit-Position: refs/heads/master@{#49390} --- src/inspector/v8-console.cc | 7 ++++--- src/inspector/v8-console.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/inspector/v8-console.cc b/src/inspector/v8-console.cc index fb20a9466c..7a0caf08a1 100644 --- a/src/inspector/v8-console.cc +++ b/src/inspector/v8-console.cc @@ -663,9 +663,10 @@ v8::Local V8Console::createCommandLineAPI( DCHECK(success); USE(success); - // TODO(dgozman): this CommandLineAPIData instance leaks. Use PodArray maybe? - v8::Local data = - v8::External::New(isolate, new CommandLineAPIData(this, sessionId)); + v8::Local data = + v8::ArrayBuffer::New(isolate, sizeof(CommandLineAPIData)); + *static_cast(data->GetContents().Data()) = + CommandLineAPIData(this, sessionId); createBoundFunctionProperty(context, commandLineAPI, data, "dir", &V8Console::call<&V8Console::Dir>, "function dir(value) { [Command Line API] }"); diff --git a/src/inspector/v8-console.h b/src/inspector/v8-console.h index a47a0b7cad..ba4dfe328b 100644 --- a/src/inspector/v8-console.h +++ b/src/inspector/v8-console.h @@ -108,14 +108,14 @@ class V8Console : public v8::debug::ConsoleDelegate { int)> static void call(const v8::FunctionCallbackInfo& info) { CommandLineAPIData* data = static_cast( - info.Data().As()->Value()); + info.Data().As()->GetContents().Data()); (data->first->*func)(info, data->second); } template static void call(const v8::FunctionCallbackInfo& info) { CommandLineAPIData* data = static_cast( - info.Data().As()->Value()); + info.Data().As()->GetContents().Data()); v8::debug::ConsoleCallArguments args(info); (data->first->*func)(args, v8::debug::ConsoleContext()); }