Skip to content

Commit 88d9676

Browse files
yashLadhatargos
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 92348a9 commit 88d9676

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
@@ -343,9 +343,10 @@ Environment::Environment(IsolateData* isolate_data,
343343
// easier to modify them after Environment creation. The defaults are
344344
// part of the per-Isolate option set, for which in turn the defaults are
345345
// part of the per-process option set.
346-
options_.reset(new EnvironmentOptions(*isolate_data->options()->per_env));
347-
inspector_host_port_.reset(
348-
new ExclusiveAccess<HostPort>(options_->debug_options().host_port));
346+
options_ = std::make_shared<EnvironmentOptions>(
347+
*isolate_data->options()->per_env);
348+
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
349+
options_->debug_options().host_port);
349350

350351
if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
351352
set_abort_on_uncaught_exception(false);

0 commit comments

Comments
 (0)