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 <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>
  • Loading branch information
yashLadha authored and danielleadams committed Feb 16, 2021
1 parent acabe08 commit 354df9e
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 @@ -379,9 +379,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 354df9e

Please sign in to comment.