Skip to content

Commit

Permalink
src: use make_shared for safe allocation
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
yashLadha authored and targos committed May 1, 2021
1 parent 92348a9 commit 88d9676
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ Environment::Environment(IsolateData* isolate_data,
// easier to modify them after Environment creation. The defaults are
// part of the per-Isolate option set, for which in turn the defaults are
// part of the per-process option set.
options_.reset(new EnvironmentOptions(*isolate_data->options()->per_env));
inspector_host_port_.reset(
new ExclusiveAccess<HostPort>(options_->debug_options().host_port));
options_ = std::make_shared<EnvironmentOptions>(
*isolate_data->options()->per_env);
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
options_->debug_options().host_port);

if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
set_abort_on_uncaught_exception(false);
Expand Down

0 comments on commit 88d9676

Please sign in to comment.