Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 44d5ecf

Browse filesBrowse files
fhinkelgibfahn
authored andcommitted
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: #17020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
1 parent bb5a3aa commit 44d5ecf
Copy full SHA for 44d5ecf

File tree

Expand file treeCollapse file tree

2 files changed

+8
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-6
lines changed
Open diff view settings
Collapse file

‎src/inspector_agent.cc‎

Copy file name to clipboardExpand all lines: src/inspector_agent.cc
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,19 @@ class InspectorTimer {
261261
}
262262

263263
static void TimerClosedCb(uv_handle_t* uvtimer) {
264-
InspectorTimer* timer =
264+
std::unique_ptr<InspectorTimer> timer(
265265
node::ContainerOf(&InspectorTimer::timer_,
266-
reinterpret_cast<uv_timer_t*>(uvtimer));
267-
delete timer;
266+
reinterpret_cast<uv_timer_t*>(uvtimer)));
267+
// Unique_ptr goes out of scope here and pointer is deleted.
268268
}
269269

270270
~InspectorTimer() {}
271271

272272
uv_timer_t timer_;
273273
V8InspectorClient::TimerCallback callback_;
274274
void* data_;
275+
276+
friend std::unique_ptr<InspectorTimer>::deleter_type;
275277
};
276278

277279
class InspectorTimerHandle {
Collapse file

‎src/inspector_io.cc‎

Copy file name to clipboardExpand all lines: src/inspector_io.cc
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ int CloseAsyncAndLoop(uv_async_t* async) {
114114

115115
// Delete main_thread_req_ on async handle close
116116
void ReleasePairOnAsyncClose(uv_handle_t* async) {
117-
AsyncAndAgent* pair = node::ContainerOf(&AsyncAndAgent::first,
118-
reinterpret_cast<uv_async_t*>(async));
119-
delete pair;
117+
std::unique_ptr<AsyncAndAgent> pair(node::ContainerOf(&AsyncAndAgent::first,
118+
reinterpret_cast<uv_async_t*>(async)));
119+
// Unique_ptr goes out of scope here and pointer is deleted.
120120
}
121121

122122
} // namespace

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.