src: use smart pointer instead of new and delete
Use an std::unique_ptr for variables that are deleted right after creation. Since the destructor of InspectorTimer is private but needed by the unique_ptr, define deleter_type as friend. PR-URL: https://github.com/nodejs/node/pull/17020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This commit is contained in:
parent
c661dad086
commit
f96abea88e
@ -261,10 +261,10 @@ class InspectorTimer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void TimerClosedCb(uv_handle_t* uvtimer) {
|
static void TimerClosedCb(uv_handle_t* uvtimer) {
|
||||||
InspectorTimer* timer =
|
std::unique_ptr<InspectorTimer> timer(
|
||||||
node::ContainerOf(&InspectorTimer::timer_,
|
node::ContainerOf(&InspectorTimer::timer_,
|
||||||
reinterpret_cast<uv_timer_t*>(uvtimer));
|
reinterpret_cast<uv_timer_t*>(uvtimer)));
|
||||||
delete timer;
|
// Unique_ptr goes out of scope here and pointer is deleted.
|
||||||
}
|
}
|
||||||
|
|
||||||
~InspectorTimer() {}
|
~InspectorTimer() {}
|
||||||
@ -272,6 +272,8 @@ class InspectorTimer {
|
|||||||
uv_timer_t timer_;
|
uv_timer_t timer_;
|
||||||
V8InspectorClient::TimerCallback callback_;
|
V8InspectorClient::TimerCallback callback_;
|
||||||
void* data_;
|
void* data_;
|
||||||
|
|
||||||
|
friend std::unique_ptr<InspectorTimer>::deleter_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InspectorTimerHandle {
|
class InspectorTimerHandle {
|
||||||
|
@ -114,9 +114,9 @@ int CloseAsyncAndLoop(uv_async_t* async) {
|
|||||||
|
|
||||||
// Delete main_thread_req_ on async handle close
|
// Delete main_thread_req_ on async handle close
|
||||||
void ReleasePairOnAsyncClose(uv_handle_t* async) {
|
void ReleasePairOnAsyncClose(uv_handle_t* async) {
|
||||||
AsyncAndAgent* pair = node::ContainerOf(&AsyncAndAgent::first,
|
std::unique_ptr<AsyncAndAgent> pair(node::ContainerOf(&AsyncAndAgent::first,
|
||||||
reinterpret_cast<uv_async_t*>(async));
|
reinterpret_cast<uv_async_t*>(async)));
|
||||||
delete pair;
|
// Unique_ptr goes out of scope here and pointer is deleted.
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user