diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index d5b3b43ec22979..215e91873a3a70 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -261,10 +261,10 @@ class InspectorTimer { } static void TimerClosedCb(uv_handle_t* uvtimer) { - InspectorTimer* timer = + std::unique_ptr timer( node::ContainerOf(&InspectorTimer::timer_, - reinterpret_cast(uvtimer)); - delete timer; + reinterpret_cast(uvtimer))); + // Unique_ptr goes out of scope here and pointer is deleted. } ~InspectorTimer() {} @@ -272,6 +272,8 @@ class InspectorTimer { uv_timer_t timer_; V8InspectorClient::TimerCallback callback_; void* data_; + + friend std::unique_ptr::deleter_type; }; class InspectorTimerHandle { diff --git a/src/inspector_io.cc b/src/inspector_io.cc index 73f0419ead6545..a870c0a2634452 100644 --- a/src/inspector_io.cc +++ b/src/inspector_io.cc @@ -114,9 +114,9 @@ int CloseAsyncAndLoop(uv_async_t* async) { // Delete main_thread_req_ on async handle close void ReleasePairOnAsyncClose(uv_handle_t* async) { - AsyncAndAgent* pair = node::ContainerOf(&AsyncAndAgent::first, - reinterpret_cast(async)); - delete pair; + std::unique_ptr pair(node::ContainerOf(&AsyncAndAgent::first, + reinterpret_cast(async))); + // Unique_ptr goes out of scope here and pointer is deleted. } } // namespace