Skip to content

Commit 354df9e

Browse files
yashLadhadanielleadams
authored andcommitted
src: use make_shared for safe allocation
Using the reset does a double allocation and is error prone if some exception occured which is very unlikely but can happen. make_shared_ptr gives hedge over this and handle the failure in allocation. PR-URL: #37139 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent acabe08 commit 354df9e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/env.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,10 @@ Environment::Environment(IsolateData* isolate_data,
379379
// easier to modify them after Environment creation. The defaults are
380380
// part of the per-Isolate option set, for which in turn the defaults are
381381
// part of the per-process option set.
382-
options_.reset(new EnvironmentOptions(*isolate_data->options()->per_env));
383-
inspector_host_port_.reset(
384-
new ExclusiveAccess<HostPort>(options_->debug_options().host_port));
382+
options_ = std::make_shared<EnvironmentOptions>(
383+
*isolate_data->options()->per_env);
384+
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
385+
options_->debug_options().host_port);
385386

386387
if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
387388
set_abort_on_uncaught_exception(false);

0 commit comments

Comments
 (0)