Skip to content

Commit 36cc0ee

Browse files
yashLadhaTrott
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 5ef4c64 commit 36cc0ee

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
@@ -375,9 +375,10 @@ Environment::Environment(IsolateData* isolate_data,
375375
// easier to modify them after Environment creation. The defaults are
376376
// part of the per-Isolate option set, for which in turn the defaults are
377377
// part of the per-process option set.
378-
options_.reset(new EnvironmentOptions(*isolate_data->options()->per_env));
379-
inspector_host_port_.reset(
380-
new ExclusiveAccess<HostPort>(options_->debug_options().host_port));
378+
options_ = std::make_shared<EnvironmentOptions>(
379+
*isolate_data->options()->per_env);
380+
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
381+
options_->debug_options().host_port);
381382

382383
if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
383384
set_abort_on_uncaught_exception(false);

0 commit comments

Comments
 (0)